You are not logged in.
Trilby,
Yeah, turns out that and the "--unneeded" flag were what I was looking for. Thank you, and sorry for posting a useless script.
Offline
Yeah, turns out that and the "--unneeded" flag were what I was looking for. Thank you, and sorry for posting a useless script.
It wasn't useless. You learned something and I learned something.
Offline
As usual, iBus was not working as advertised.
gnome-control-center keyboard sets the keys (Shift)+Super+Space to cycle input sources--but nothing recognizes the keys, whatever is set. Gnome-shell might be expected to make the connection somehow. However, iBus does recognize its own configurable key, set by ibus-setup.
I don't know what GNOME devs have in mind with two places to configure keys for the same purpose and one that doesn't work but, whatever, making my own solution (again).
ibus-toggle
#! /bin/bash
if [ -n "$(pidof ibus-daemon)" ]; then
ibus exit
else
ibus-daemon -drx
fi
To emulate the intended behavior, fix a few things in gnome-control-center keyboard:
Disable non-functional (Shift)+Super+Space shortcuts:
Add a new custom shortcut to toggle iBus:
Cycle individual input methods with the key set by ibus-setup:
ibus-toggle also comes in handy with those applications that do not recognize iBus's input.
Last edited by quequotion (2016-03-20 12:13:04)
makepkg-optimize · indicator-powersave · pantheon-{3d,lite} · {pantheon,higan}-qq
Offline
simple script to toggle touchpad on/off, (used with keybinding to Fn+F5)
#!/bin/bash
pad=$(synclient | grep TouchpadOff | awk -F= '{print $2}')
if [ ${pad} == 0 ]; then synclient TouchpadOff=1
fi
if [ ${pad} == 1 ]; then synclient TouchpadOff=0
fi
Arch is home!
https://github.com/Docbroke
Offline
I use a similar script, but i also move the cursor out of view / back to the center of the screen.
#!/bin/bash
TPSTATUS=$(synclient -l | grep -c 'TouchpadOff.*=.*0')
# Move mouse out of the way, if xdotool is present
if [[ -x /usr/bin/xdotool ]]; then
if [[ $TPSTATUS -eq 0 ]]; then
/usr/bin/xdotool mousemove --polar 0 0
else
/usr/bin/xdotool mousemove --polar 135 5000
fi
fi
synclient TouchpadOff=$TPSTATUS
Offline
simple script to toggle touchpad on/off, (used with keybinding to Fn+F5)
You can do it all in awk (trackpad-toggle)
#!/bin/sh
synclient TouchpadOff=$(synclient -l | awk '/TouchpadOff/ {print !$3}')
grep -c as ^ works too.
Last edited by Alad (2016-03-20 11:38:54)
Mods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby
Offline
that's awksome!
I'm just taking first baby-steps in bash-world!
Arch is home!
https://github.com/Docbroke
Offline
This isn't bash though, it's using ! to negate the value under $3 in awk, thus if the value is 0, it returns 1, and if it's 1 (or anything non-zero) it returns 0. (NB. Awk also uses $1, $2, .., $n notation but for fields.)
PS: See http://wiki.bash-hackers.org/syntax/expansion/cmdsubst
Last edited by Earnestly (2016-03-20 12:33:26)
Offline
Here is my tocuchpad toggle, with notifications
#! /usr/bin/bash
foo=$( synclient | grep TouchpadOff | grep 0 )
var=$?
if [ $var -eq 0 ]
then
notify-send "Touchpad State" off
synclient TouchpadOff=1
else
notify-send "Touchpad State" on
synclient TouchpadOff=0
fi
I bind it to alt-space. Seems we all have the same problem
Last edited by ewaller (2016-03-20 15:52:43)
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way
Offline
Seems we all have the same problem
Not me. In my xinitrc:
synclient TouchpadOff=1
Problem solved
(I love trackpoints.)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
This isn't bash though, it's using ! to negate the value under $3 in awk, thus if the value is 0, it returns 1, and if it's 1 (or anything non-zero) it returns 0. (NB. Awk also uses $1, $2, .., $n notation but for fields.)
I can't believe I actually understand and used awk at some point in my life. It's an amazing and super powerful language but... I think it took, like, 3 weeks for me to understand it and only 1 week for me to forget everything I learned.
Offline
I can't believe I actually understand and used awk at some point in my life. It's an amazing and super powerful language but... I think it took, like, 3 weeks for me to understand it and only 1 week for me to forget everything I learned.
info gawk
also: https://www.youtube.com/watch?v=Sg4U4r_AgJU
Last edited by Alad (2016-03-22 23:00:42)
Mods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby
Offline
I got some inspiration from "grep -c" usage and created one more script to run slock on lid-close. Here is the script
#!/bin/bash
# LID=$(cat /proc/acpi/button/lid/LID0/state | awk '{print $2}')
LID=$(cat /proc/acpi/button/lid/LID0/state | grep -c 'state:.*open')
if [ ${LID} == 0 ]; then slock
fi
and here is the service file
[Unit]
Description=slock on lid close
[Service]
Type=simple
User=sharad
Environment=DISPLAY=:0
ExecStart=/home/sharad/bin/lid
Restart=always
RestartSec=1
I am almost sure that I am not doing this right way, but it works, and I am happy to avoid acpid/xss-lock/xautolock etc! Suggestions are welcome!
EDIT: oops! the script is alright but service is wrongly configured, as it will keep triggering slock every second, when lid is closed, needs some improvement.
EDIT2: using this script with conky, systemd-service file posted above fails after single execution of slock!
Last edited by Docbroke (2016-03-23 09:59:30)
Arch is home!
https://github.com/Docbroke
Offline
Spare the feline:
# LID=$(awk '{print $2}' /proc/acpi/button/lid/LID0/state)
LID=$(grep -c 'state:.*open' /proc/acpi/button/lid/LID0/state)
Simpler:
(( LID = 0)) && slock
Offline
yeh spared the feline !
however "(( LID = 0)) && slock" didn't work
EDIT: worked after changing operator to == as suggested in next post
Last edited by Docbroke (2016-03-23 10:02:28)
Arch is home!
https://github.com/Docbroke
Offline
My bad: the operator is ==.
Offline
So you've learned of grep -c, but apparently not grep -q:
grep -q 'state:.*open' /proc/acpi/button/lid/LID0/state || slock
This would be a bit better with a different match and a && instead of || - is the alternative to .*open *closed? If so the following would be best:
grep -q 'state:.*closed' /proc/acpi/button/lid/LID0/state && slock
The reason being the first version with the || will run slock if grep fails for some unexpected reason like that file not existing or being accessible.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
People hardcoding DISPLAY variables gets a bit old, at least for those who use multiple display servers. I use this:
#!/bin/bash
pid=$(pgrep -t tty$(fgconsole) xinit)
pid=$(pgrep -P $pid -n)
import_environment() {
(( pid )) && for var; do
IFS='=' read key val < <(egrep -z "$var" /proc/$pid/environ)
printf -v "$key" %s "$val"
[[ ${!key} ]] && export "$key"
done
}
import_environment XAUTHORITY USER DISPLAY
xscreensaver-command -activate
xscreensaver-command -lock
Assumes you use xinit to start your WM. /usr/lib/systemd/system-sleep snippet:
#!/bin/bash
case $1/$2 in
pre/*) xscreensaver-asroot ;;
esac
If you want it only to happen when you close the lid, use grep as above, or:
[[ $(awk '$2 ~ /closed/' /proc/acpi/button/lid/LID0/state) ]] && ...
Last edited by Alad (2016-03-23 12:32:38)
Mods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby
Offline
Do I come from another dimension, or is the -q switch redundant in this instance? If I'm not still with a fever from that damn flue, grep returns true on a find and false on no finds and/or errors.
Offline
Do I come from another dimension, or is the -q switch redundant in this instance? If I'm not still with a fever from that damn flue, grep returns true on a find and false on no finds and/or errors.
grep without the -q switch would also print the matching line(s).
Offline
read -r _ state < /proc/acpi/button/lid/LID0/state
case $state in
...
esac
Why overcomplicate everything?
Edit: Although just using grep's exit status is better if that's all you need
Last edited by Earnestly (2016-03-23 13:54:19)
Offline
@Trilby, thanks for "grep -q" idea, and yeh, closed is the another alternnative scenario for lid.
Arch is home!
https://github.com/Docbroke
Offline
Have a look at expac.
Have a look at the title of this topic
Anyway, I just wrote a simple wrapper for applications that don't support multi-threading. This example encodes flac to aac, but it can really be used for anything.
#!/bin/bash
set -e; cd `dirname $0`
MAXTHREADS=6
t=()
while read -d '' p
do
mkdir -p "aac.tmp/${p%/*}"
flac -dc "$p" | fdkaac - -o"aac.tmp/$p" & t=(${t[*]} $!)
[[ ${#t[*]} -lt $MAXTHREADS ]] && continue
wait ${t[0]} && unset t[0]
done < <(find flac/ -type f -name \*.flac -print0)
# wait for running threads
while [[ ${#t[*]} -gt 0 ]]; do wait ${t[0]} && unset t[0]; done
It uses an array, and keeps the # of threads consistent by waiting for the first thread when the maximum # is reached. Works best when all sub-processes take roughly the same time
Last edited by Spider.007 (2016-04-10 12:38:24)
Offline
#!/usr/bin/env bash
# Play subtitles for a film if they exist
movie="$1"
mdir="${movie%/*}"
name="${movie##*/}"
cd "$mdir"
for file in *; do
if [[ ${file%.*} == ${name%.*} ]]; then
title="${file%.*}"
for match in "$title"*; do
if [[ $match =~ @*.(ass|srt|sub) ]]; then
subtitles="$match"
fi
done
fi
done
if [[ -n $subtitles ]]; then
mpv --subfile="$subtitles" "$name"
else
printf "%s\n" "No subs found, playing film anyway..."
mpv "$name"
fi
# vim:set sw=2 ts=2 et:
Prompted by this: http://unix.stackexchange.com/questions … nfig-files
Offline
...
# Quotes not necessary here
movie="$1"
mdir="${movie%/*}"
name="${movie##*/}"
...
# It is a bit anal but naked globs should have ./ prefixed, i.e. for a in ./*
# See <http://www.dwheeler.com/essays/filenames-in-shell.html>
# Edit: Also consider using nullglob if you're using bash.
for file in *; do
# The RHS of the if statement needs to be quoted.
# See <http://mywiki.wooledge.org/Quotes#When_Should_You_Quote.3F>
if [[ ${file%.*} == ${name%.*} ]]; then
# Unnecessary quoting here
title="${file%.*}"
# And here
subtitles="$match"
# No need for -n here
if [[ -n $subtitles ]]; then
...
Last edited by Earnestly (2016-05-01 22:36:27)
Offline