diff options
author | katherine <shmibs@shmibbles.me> | 2017-11-08 01:47:34 -0700 |
---|---|---|
committer | katherine <shmibs@shmibbles.me> | 2017-11-08 01:47:34 -0700 |
commit | 5d57322f71a9f3193133c1be1d5fe938b5cb6e56 (patch) | |
tree | 3ea6f992a1e7a25608af06bd2a9bc074d2e17ff4 /.config/herbstluftwm/maim.sh | |
parent | 7f19a384e2f683cfec0186845af8837124184785 (diff) | |
download | dotfiles-5d57322f71a9f3193133c1be1d5fe938b5cb6e56.tar.gz |
add pass and maim support to herbstluftwm
Diffstat (limited to '.config/herbstluftwm/maim.sh')
-rwxr-xr-x | .config/herbstluftwm/maim.sh | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/.config/herbstluftwm/maim.sh b/.config/herbstluftwm/maim.sh new file mode 100755 index 0000000..a569460 --- /dev/null +++ b/.config/herbstluftwm/maim.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env zsh + +local mpat='^(send|clipboard|normal)$' + +local mode='normal' +local selection + +local args +zparseopts -D -E -M -A args \ + m: -mode=m \ + s -selection=s + +local optarg +for opt in ${(@k)args}; do + unset optarg + [[ -z $args[$opt] ]] || optarg=$args[$opt] + case $opt in + -m) + [[ ! $(echo $optarg | grep -oE "$mpat") ]] \ + && echo "err: bad mode" && exit + mode=$optarg + ;; + + -s) selection=s ;; + esac +done + +[[ ${#@} -gt 0 ]] && echo "err: unrecognised arguments" && exit + +local year +local stamp +date +%Y | read year +date +%s | read stamp + +local fname="$HOME/images/scrot/$year/${year}-${stamp}.png" + +mkdir -p $HOME/images/scrot/$year + +if [[ $mode == clipboard ]]; then + maim -u${selection} | xclip -selection clipboard -t image/png + exit +fi + +maim -u${selection} $fname + +if [[ $mode == send ]]; then + [[ -f $fname ]] \ + && optipng $fname \ + && send $fname \ + && notify-send "maim: sent ${fname:t} to /tmp/" \ + || notify-send "maim: send to /tmp/ failed" +fi |