From df66e00727e78229a2e4700b864a775d90eebb1e Mon Sep 17 00:00:00 2001 From: Sheldon Lee Date: Mon, 24 Jan 2022 05:11:35 +0800 Subject: [PATCH] Scripts now portable betwwen Xorg/Wayland. If in Wayland, the "bemenu" alternative should be used instead of "dmenu" or "rofi". --- .config/wm_scripts/menucmd | 55 ++++++++++++++++++++++ .config/wm_scripts/passrofi | 3 +- .config/wm_scripts/screenshot.sh | 80 ++++++++++++++++++++++++++------ 3 files changed, 121 insertions(+), 17 deletions(-) create mode 100755 .config/wm_scripts/menucmd diff --git a/.config/wm_scripts/menucmd b/.config/wm_scripts/menucmd new file mode 100755 index 0000000..5eb5702 --- /dev/null +++ b/.config/wm_scripts/menucmd @@ -0,0 +1,55 @@ +#!/bin/sh +base03="#002b36" +base02="#073642" +base01="#586e75" +base00="#657b83" +base0="#839496" +base1="#93a1a1" +base2="#eee8d5" +base3="#fdf6e3" +yellow="#b58900" +orange="#cb4b16" +red="#dc322f" +magenta="#d33682" +violet="#6c71c4" +blue="#268bd2" +cyan="#2aa198" +green="#859900" + +bemenu_cmd() +{ + bemenu -l 10 --scrollbar always\ + --fn "SourceCodePro Semibold 11px"\ + --tb $base02 --tf $green\ + --fb $base03 --ff $base0\ + --nb $base03 --nf $base0\ + --sb $base02 --sf $cyan\ + --hb $base02 --hf $cyan\ + --scb $base02 --scf $cyan + $@ +} + +dmenu_cmd() +{ + dmenu -p dmenu -l 10\ + -fn "SourceCodeProSemibold-9"\ + -nb $base03 -nf $base0\ + -sb $base02 -sf $cyan\ + $@ +} + +rofi_cmd() +{ + rofi -dmenu +} + +if [[ -n $WAYLAND_DISPLAY ]]; then + bemenu_cmd $@ +elif [[ -n $DISPLAY ]]; then + rofi_cmd $@ +else + echo "Error: No Wayland or X11 display detected" >&2 + exit 1 +fi + + diff --git a/.config/wm_scripts/passrofi b/.config/wm_scripts/passrofi index 50172cc..de8ef05 100755 --- a/.config/wm_scripts/passrofi +++ b/.config/wm_scripts/passrofi @@ -2,13 +2,12 @@ shopt -s nullglob globstar -dmenu="rofi" prefix=${PASSWORD_STORE_DIR-~/.password-store} password_files=( "$prefix"/**/*.gpg ) password_files=( "${password_files[@]#"$prefix"/}" ) password_files=( "${password_files[@]%.gpg}" ) -password=$(printf '%s\n' "${password_files[@]}" | "$dmenu" -dmenu "$@") +password=$(printf '%s\n' "${password_files[@]}" | "$HOME/.config/wm_scripts/menucmd" "$@") [[ -n $password ]] || exit diff --git a/.config/wm_scripts/screenshot.sh b/.config/wm_scripts/screenshot.sh index 5b16093..505e5e5 100755 --- a/.config/wm_scripts/screenshot.sh +++ b/.config/wm_scripts/screenshot.sh @@ -4,30 +4,26 @@ # Script to take screenshots or gifs # +menucmd=$HOME/.config/wm_scripts/menucmd +grimshot=/usr/share/sway-git/scripts/grimshot + +date_format='%Y-%m-%d_%H-%M-%S' + scrot_dir=$HOME/screenshots gif_dir=$scrot_dir/gifs -date_format='%Y-%m-%d_%H-%M-%S' [ -d $scrot_dir ] || mkdir $scrot_dir [ -d $gif_dir ] || mkdir $gif_dir -main() { - prompt_main -} - -# prompt with rofi -prompt_main() { +# prompt options in Xorg +prompt_xorg() { options=" 1) Fullscreen\n\ 2) Selection\n\ 3) Record screen " - #echo -e $options - # -i case insensitive - # -l vertical lines - option=$(echo -e $options | rofi -dmenu) + option=$(echo -e $options | $menucmd) - #echo "\"$option\"" case $option in 1*) sleep 0.5 @@ -42,13 +38,38 @@ prompt_main() { esac } +# prompt options in Wayland +prompt_wayland(){ + options=" +1) Fullscreen\n\ +2) Selection\n\ +3) Window\n\ + " + + option=$(echo -e $options | $menucmd) + + # use grimshot here + case $option in + 1*) + sleep 0.5 + f_grimshot + ;; + 2*) + s_grimshot + ;; + 3*) + w_grimshot + ;; + esac +} + prompt_gif() { options=" 10s\n\ 30s\n\ 60s " - option=$(echo -e $options | rofi -dmenu) + option=$(echo -e $options | menucmd) case $option in 10s) @@ -63,7 +84,6 @@ prompt_gif() { esac } - # screenshots using scrot s_scrot() { name=$(date +${date_format}_sel.png) @@ -79,6 +99,28 @@ f_scrot() { xclip -sel clip $path -t image/png } +# screenshots using grimshot +f_grimshot() { + name=$(date +${date_format}_full.png) + path="${scrot_dir}/${name}" + $grimshot save output $path && + wl-copy --type image/png < $path +} + +s_grimshot() { + name=$(date +${date_format}_full.png) + path="${scrot_dir}/${name}" + $grimshot save area $path && + wl-copy --type image/png < $path +} + +w_grimshot() { + name=$(date +${date_format}_full.png) + path="${scrot_dir}/${name}" + $grimshot save window $path && + wl-copy --type image/png < $path +} + # screen recorder byzanz_gif() { name=$(date +${date_format}.gif) @@ -86,4 +128,12 @@ byzanz_gif() { byzanz-record -c -d $1 --delay=0 $path } -main "$@" +if [[ -n $WAYLAND_DISPLAY ]]; then + prompt_wayland +elif [[ -n $DISPLAY ]]; then + prompt_xorg +else + echo "Error: No Wayland or X11 display detected" >&2 + exit 1 +fi +