Scripts now portable betwwen Xorg/Wayland.

If in Wayland, the "bemenu" alternative should be used instead of
"dmenu" or "rofi".
This commit is contained in:
Sheldon Lee 2022-01-24 05:11:35 +08:00
parent b839f0d05d
commit df66e00727
3 changed files with 121 additions and 17 deletions

55
.config/wm_scripts/menucmd Executable file
View File

@ -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

View File

@ -2,13 +2,12 @@
shopt -s nullglob globstar shopt -s nullglob globstar
dmenu="rofi"
prefix=${PASSWORD_STORE_DIR-~/.password-store} prefix=${PASSWORD_STORE_DIR-~/.password-store}
password_files=( "$prefix"/**/*.gpg ) password_files=( "$prefix"/**/*.gpg )
password_files=( "${password_files[@]#"$prefix"/}" ) password_files=( "${password_files[@]#"$prefix"/}" )
password_files=( "${password_files[@]%.gpg}" ) 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 [[ -n $password ]] || exit

View File

@ -4,30 +4,26 @@
# Script to take screenshots or gifs # 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 scrot_dir=$HOME/screenshots
gif_dir=$scrot_dir/gifs gif_dir=$scrot_dir/gifs
date_format='%Y-%m-%d_%H-%M-%S'
[ -d $scrot_dir ] || mkdir $scrot_dir [ -d $scrot_dir ] || mkdir $scrot_dir
[ -d $gif_dir ] || mkdir $gif_dir [ -d $gif_dir ] || mkdir $gif_dir
main() { # prompt options in Xorg
prompt_main prompt_xorg() {
}
# prompt with rofi
prompt_main() {
options=" options="
1) Fullscreen\n\ 1) Fullscreen\n\
2) Selection\n\ 2) Selection\n\
3) Record screen 3) Record screen
" "
#echo -e $options
# -i case insensitive option=$(echo -e $options | $menucmd)
# -l vertical lines
option=$(echo -e $options | rofi -dmenu)
#echo "\"$option\""
case $option in case $option in
1*) 1*)
sleep 0.5 sleep 0.5
@ -42,13 +38,38 @@ prompt_main() {
esac 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() { prompt_gif() {
options=" options="
10s\n\ 10s\n\
30s\n\ 30s\n\
60s 60s
" "
option=$(echo -e $options | rofi -dmenu) option=$(echo -e $options | menucmd)
case $option in case $option in
10s) 10s)
@ -63,7 +84,6 @@ prompt_gif() {
esac esac
} }
# screenshots using scrot # screenshots using scrot
s_scrot() { s_scrot() {
name=$(date +${date_format}_sel.png) name=$(date +${date_format}_sel.png)
@ -79,6 +99,28 @@ f_scrot() {
xclip -sel clip $path -t image/png 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 # screen recorder
byzanz_gif() { byzanz_gif() {
name=$(date +${date_format}.gif) name=$(date +${date_format}.gif)
@ -86,4 +128,12 @@ byzanz_gif() {
byzanz-record -c -d $1 --delay=0 $path 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