various tweaks and refactors

This commit is contained in:
Von Random 2020-02-11 15:10:03 +03:00
parent 2fb479e4ec
commit 8e5f4e4d9e
7 changed files with 31 additions and 24 deletions

View file

@ -20,7 +20,6 @@ import subprocess
import sys import sys
import yaml import yaml
def run_cmd(cmd, stdin=subprocess.PIPE, data=None): def run_cmd(cmd, stdin=subprocess.PIPE, data=None):
proc = subprocess.Popen( proc = subprocess.Popen(
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=stdin cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=stdin
@ -35,24 +34,22 @@ def run_cmd(cmd, stdin=subprocess.PIPE, data=None):
sys.stderr.write('\n'.join(err_msg) + '\n') sys.stderr.write('\n'.join(err_msg) + '\n')
return stdout return stdout
def run_multicmd(cmds):
for cmd in cmds:
run_cmd(cmd)
def main(): def main():
config_path = sys.argv[1] config_path = sys.argv[1]
with open(config_path, mode='r') as config: with open(config_path, mode='r') as config:
conf = yaml.load(config.read()) conf = yaml.safe_load(config.read())
dmenu_cmd = ['/usr/bin/dmenu', '-p', conf.get('name', 'N/A')] + sys.argv[2:] dmenu_cmd = ['/usr/bin/dmenu', '-p', conf.get('name', 'N/A')] + sys.argv[2:]
dmenu_opt = '\n'.join(conf['multicmd']).encode() dmenu_opt = '\n'.join(conf['multicmd']).encode()
selection = run_cmd(dmenu_cmd, data=dmenu_opt).decode('UTF-8') selection = run_cmd(dmenu_cmd, data=dmenu_opt).decode('UTF-8')
#selection = sys.argv[2]
if not selection in conf['multicmd']: if not selection in conf['multicmd']:
sys.exit(1) sys.exit(1)
run_multicmd(conf.get('cmd_pre', tuple())) cmds =\
run_multicmd(conf['multicmd'][selection]) conf.get('cmd_pre', list()) +\
run_multicmd(conf.get('cmd_post', tuple())) conf['multicmd'][selection] +\
conf.get('cmd_post', list())
for cmd in cmds:
run_cmd(cmd)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -28,5 +28,5 @@ if [[ $typeit -eq 0 ]]; then
fi fi
notify-send -a "pass" "$msg" "$password" notify-send -a "pass" "$msg" "$password"
else else
pass show "$password" | { read -r pass; printf %s "$pass"; } | xdotool type --clearmodifiers --file - gopass show "$password" | { read -r pass; printf %s "$pass"; } | xdotool type --clearmodifiers --file -
fi fi

View file

@ -7,4 +7,4 @@ case $1 in
*) printf "%s is a wrong noise type\n" $1 >&2 ; exit 1 ;; *) printf "%s is a wrong noise type\n" $1 >&2 ; exit 1 ;;
esac esac
play -n synth $noise_type exec play -n synth $noise_type

View file

@ -1,6 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# run with more compatible TERM value # run with more compatible TERM value
typeset -A terms=( typeset -A terms=(
[xterm-kitty]='xterm'
[rxvt-unicode-256color]='rxvt-unicode' [rxvt-unicode-256color]='rxvt-unicode'
[st-256color]='xterm-256color' [st-256color]='xterm-256color'
[tmux-256color]='screen.xterm-new' [tmux-256color]='screen.xterm-new'

4
tvim
View file

@ -9,6 +9,6 @@ error() {
} }
termbin=$(command -v default-terminal-emulator) || termbin=$(command -v xterm) || error "No terminal found!" termbin=$(command -v default-terminal-emulator) || termbin=$(command -v xterm) || error "No terminal found!"
vimbin=$(command -v vim) || error "No vim binary found!" vimbin=$(command -v nvim) || vimbin=$(command -v vim) || vimbin=$(command -v vi) || error "No vim binary found!"
exec "$termbin" -c tvim -e "$vimbin" "${vimopt[@]}" "$@" &>/dev/null & disown exec "$termbin" -e "$vimbin" "${vimopt[@]}" "$@" &>/dev/null & disown

View file

@ -1,11 +1,8 @@
#!/usr/bin/zsh #!/usr/bin/zsh
INDEX="$HOME/vimwiki/index.md" INDEX="$HOME/vimwiki/index.md"
WIKIOPTS="[{'path': '$HOME/vimwiki/', 'syntax': 'markdown', 'ext': '.md'}]"
VIMOPTS=( VIMOPTS=(
'-c' 'set titlestring=vimwiki' '-c' 'set titlestring=vimwiki'
'-c' "let g:vimwiki_list = $WIKIOPTS" '-c' 'VimwikiIndex'
'-c' 'packadd vimwiki'
'-c' "e $INDEX"
) )
case $1 in case $1 in

View file

@ -3,6 +3,17 @@
pidfile=${XDG_RUNTIME_DIR-/run/user/$UID}/xscreensaver-companion.pid pidfile=${XDG_RUNTIME_DIR-/run/user/$UID}/xscreensaver-companion.pid
trap "rm -f $pidfile" INT KILL trap "rm -f $pidfile" INT KILL
function check_start
{
# check if the service is running and, if not, start it in the background
# and detach
if pgrep -u $USER $1 >/dev/null; then
return 0
else
$* &>/dev/null </dev/null & disown
fi
}
function init_pidfile function init_pidfile
{ {
local pid local pid
@ -23,17 +34,18 @@ function parse_actions
while read action _; do while read action _; do
case $action in case $action in
(LOCK|BLANK) (LOCK|BLANK)
/usr/bin/setxkbmap us -option setxkbmap us -option
/usr/bin/numlockx off notify-send DUNST_COMMAND_PAUSE
/usr/bin/notify-send DUNST_COMMAND_PAUSE
;; ;;
(UNBLANK) (UNBLANK)
check_start gxkb
$HOME/git/mine/vscripts/mykblayouts $HOME/git/mine/vscripts/mykblayouts
/usr/bin/notify-send DUNST_COMMAND_RESUME $HOME/.local/bin/touchpad-config
notify-send DUNST_COMMAND_RESUME
;; ;;
esac esac
done done
} }
init_pidfile init_pidfile
/usr/bin/xscreensaver-command -watch | parse_actions xscreensaver-command -watch | parse_actions