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 yaml
def run_cmd(cmd, stdin=subprocess.PIPE, data=None):
proc = subprocess.Popen(
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')
return stdout
def run_multicmd(cmds):
for cmd in cmds:
run_cmd(cmd)
def main():
config_path = sys.argv[1]
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_opt = '\n'.join(conf['multicmd']).encode()
selection = run_cmd(dmenu_cmd, data=dmenu_opt).decode('UTF-8')
#selection = sys.argv[2]
if not selection in conf['multicmd']:
sys.exit(1)
run_multicmd(conf.get('cmd_pre', tuple()))
run_multicmd(conf['multicmd'][selection])
run_multicmd(conf.get('cmd_post', tuple()))
cmds =\
conf.get('cmd_pre', list()) +\
conf['multicmd'][selection] +\
conf.get('cmd_post', list())
for cmd in cmds:
run_cmd(cmd)
if __name__ == '__main__':
main()

View file

@ -28,5 +28,5 @@ if [[ $typeit -eq 0 ]]; then
fi
notify-send -a "pass" "$msg" "$password"
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

View file

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

View file

@ -1,6 +1,7 @@
#!/usr/bin/env bash
# run with more compatible TERM value
typeset -A terms=(
[xterm-kitty]='xterm'
[rxvt-unicode-256color]='rxvt-unicode'
[st-256color]='xterm-256color'
[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!"
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
INDEX="$HOME/vimwiki/index.md"
WIKIOPTS="[{'path': '$HOME/vimwiki/', 'syntax': 'markdown', 'ext': '.md'}]"
VIMOPTS=(
'-c' 'set titlestring=vimwiki'
'-c' "let g:vimwiki_list = $WIKIOPTS"
'-c' 'packadd vimwiki'
'-c' "e $INDEX"
'-c' 'VimwikiIndex'
)
case $1 in

View file

@ -3,6 +3,17 @@
pidfile=${XDG_RUNTIME_DIR-/run/user/$UID}/xscreensaver-companion.pid
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
{
local pid
@ -23,17 +34,18 @@ function parse_actions
while read action _; do
case $action in
(LOCK|BLANK)
/usr/bin/setxkbmap us -option
/usr/bin/numlockx off
/usr/bin/notify-send DUNST_COMMAND_PAUSE
setxkbmap us -option
notify-send DUNST_COMMAND_PAUSE
;;
(UNBLANK)
check_start gxkb
$HOME/git/mine/vscripts/mykblayouts
/usr/bin/notify-send DUNST_COMMAND_RESUME
$HOME/.local/bin/touchpad-config
notify-send DUNST_COMMAND_RESUME
;;
esac
done
}
init_pidfile
/usr/bin/xscreensaver-command -watch | parse_actions
xscreensaver-command -watch | parse_actions