From e850f3a1702b4d8b9d0cfec5c07d710b5201ed29 Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Fri, 4 Aug 2023 22:36:30 +0200 Subject: edited toush to fit needs --- bin/common/toush | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'bin') diff --git a/bin/common/toush b/bin/common/toush index dd675b9..eb2d7cf 100755 --- a/bin/common/toush +++ b/bin/common/toush @@ -1,14 +1,10 @@ #!/bin/sh -# fork of -# https://codeberg.org/futxlii/bin/toush :) +# idea from https://codeberg.org/futxlii/bin/toush :) shebang='#!/bin/sh' -usage() { >&2 printf 'Usage: %s' "${0##*/}"; exit 1 ;} +[ -f "$1" ] && exit 1 -[ "$1" ] || usage -while [ "$1" ]; do - [ -f "$1" ] && usage - printf '%s\n\n' "$shebang" > "$1" && chmod +x "$1" - shift -done +printf '%s\n\n' "$shebang" > "$1" && + chmod +x "$1" && $EDITOR "$1" +grep -qv "$shebang\|^$" "$1" || rm "$1" -- cgit v1.2.3 From e9f233edd96fe850037244c0d80bec67a8b2077f Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Sun, 6 Aug 2023 14:57:01 +0200 Subject: removed 1xsearch --- bin/extra/1xsearch | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100755 bin/extra/1xsearch (limited to 'bin') diff --git a/bin/extra/1xsearch b/bin/extra/1xsearch deleted file mode 100755 index a248d38..0000000 --- a/bin/extra/1xsearch +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh - -# dependencies -which pup > /dev/null || - exit 1 - -test -z "${query:=$1}" && - query="$(cat /dev/stdin)" - -url="https://1337x.to" -query="$(echo "$query" | tr ' ' '+' )" -result="$(curl -s "$url/search/$query/1/" | - pup -p 'a attr{href}' | - grep "^/torrent" | - head -n 1)" -# result contains / as first char -curl -s "$url$result" | - pup -p 'a attr{href}' | - grep "^magnet:" | - head -n 1 -- cgit v1.2.3 From d22b27180eb394f9443860ccdf2656d2fdef56ed Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Sun, 6 Aug 2023 14:57:14 +0200 Subject: updated notify-send command --- bin/guiscripts/keyadd | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'bin') diff --git a/bin/guiscripts/keyadd b/bin/guiscripts/keyadd index 96d6d03..1df8896 100755 --- a/bin/guiscripts/keyadd +++ b/bin/guiscripts/keyadd @@ -43,16 +43,16 @@ die "HOST: $HOST" if [ "$1" = "-d" ] then ssh-add -d - < "$SSHFOLDER"/$key.pub && - notify-send "$0" "deleted $key" || - notify-send "$0" "could not delete." + notify-send "keyadd" "deleted $key" || + notify-send "keyadd" "could not delete." elif ! ssh-add -l | grep -q "$(ssh-keygen -lf "$SSHFOLDER"/$key)" then die "adding: $key" export PASSWORD="keys/$HOST/ssh/$key" export SSH_ASKPASS="$0" ssh-add - < "$SSHFOLDER"/$key && - notify-send "$0" "added $key" + notify-send "keyadd" "added $key" else die "key already added." - notify-send "$0" "key already added." + notify-send "keyadd" "key already added." fi -- cgit v1.2.3 From 171c1f519b902e1654e17bd33cb129569478f7f7 Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Sun, 6 Aug 2023 14:57:37 +0200 Subject: don't create temp file --- bin/menuscripts/mhelp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'bin') diff --git a/bin/menuscripts/mhelp b/bin/menuscripts/mhelp index e03222b..5963a88 100755 --- a/bin/menuscripts/mhelp +++ b/bin/menuscripts/mhelp @@ -1,5 +1,4 @@ #!/usr/bin/env sh -OPTIONS="/tmp/dmh_options.txt" if [ "$MENUCMD" = "tofi" ] then @@ -16,18 +15,15 @@ fi test -z "$program" && exit 1 -if $program --help > "$OPTIONS" -then - option="$(grep "^ *-[-a-zA-Z0-9]* " "$OPTIONS" | - tr -s ' ' | - sort | - uniq | - column -l 2 -t | - $menucmd | - awk '{print $1}')" -fi +option="$($program --help | + # Parse options + grep "^ *-[-a-zA-Z0-9]* " | + tr -s ' ' | + sort | uniq | + column -l 2 -t | + $menucmd | + awk '{print $1}')" test -z "$option" && exit 1 -rm -f "$OPTIONS" setsid $program $option -- cgit v1.2.3 From 5fa4e064dc48450f371a8f4ef42f58e5a437c60f Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Sun, 6 Aug 2023 14:58:44 +0200 Subject: [ytclipo] changed resolution and template --- bin/common/ytclipo | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'bin') diff --git a/bin/common/ytclipo b/bin/common/ytclipo index 263f1b3..7e7b9cc 100755 --- a/bin/common/ytclipo +++ b/bin/common/ytclipo @@ -19,8 +19,8 @@ notify-send "ytclipo" "downloading $inp" yt-dlp "$inp" \ --restrict-filenames \ -f "b" \ - -S "res:720" \ + -S "res:1080" \ -P "$HOME/vids/youtube/" \ - -o "%(title)s.%(ext)s" + -o "%(channel)s - %(title)s.%(ext)s" notify-send "ytclipo" "ytclipo
finished downloading." echo "$inp" >> /tmp/ytclipo_history -- cgit v1.2.3 From cb110575144beb4125fd1d8204c8204e6bca280f Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Mon, 7 Aug 2023 18:59:08 +0200 Subject: [goo] added option to give search query as second paramater I noticed by mistake sometimes I would type the query already. --- bin/common/goo | 9 +++++++-- config/essentials/zsh/functions.zsh | 6 +++--- 2 files changed, 10 insertions(+), 5 deletions(-) (limited to 'bin') diff --git a/bin/common/goo b/bin/common/goo index cfd03ec..2a5faad 100755 --- a/bin/common/goo +++ b/bin/common/goo @@ -15,9 +15,14 @@ VisualParadigm intellij arduino15" +if [ -n "$2" ] +then + [ -d "$2" ] && dest="$2" || opt="-q $2" +fi + for dir in $exclude; do dirs="$dirs -name \"$dir\" -o " done -cmd="find ${2:-$HOME} \(${dirs} -false \) -prune -o -type ${1:-f} -mindepth 1 -print" +cmd="find ${dest:-$HOME} \(${dirs} -false \) -prune -o -type ${1:-f} -mindepth 1 -print" -eval "$cmd" 2>/dev/null +eval "$cmd" 2>/dev/null | fzf $opt diff --git a/config/essentials/zsh/functions.zsh b/config/essentials/zsh/functions.zsh index 671e6fb..053ce8e 100644 --- a/config/essentials/zsh/functions.zsh +++ b/config/essentials/zsh/functions.zsh @@ -39,9 +39,9 @@ nnn() { test -z "$NNNLVL" && /usr/bin/nnn "$@" || exit } ranger() { test -z "$RANGER_LEVEL" && /usr/bin/ranger "$@" || exit } # googoo aliases -ff () { goo f "$1" | fzf } -fd () { goo d "$1" | fzf } -fdf () { goo f "$1" | fzf | xargs -I {} dirname "{}" } +ff () { goo f "$1" } +fd () { goo d "$1" } +fdf () { goo f "$1" | xargs -I {} dirname "{}" } o () { f="$(ff $1)" -- cgit v1.2.3 From ffb6d1aaedaa3882e356d7d58a5734b6f6a653e7 Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Fri, 11 Aug 2023 18:21:47 +0200 Subject: [mpass] added notification --- bin/menuscripts/mpass | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'bin') diff --git a/bin/menuscripts/mpass b/bin/menuscripts/mpass index a50f0fb..8153dc6 100755 --- a/bin/menuscripts/mpass +++ b/bin/menuscripts/mpass @@ -20,6 +20,8 @@ done test -z "$file" && exit 1 pass show -c "$file" && if [ -n "$WAYLAND_DISPLAY" ] && cliphist list >/dev/null -then - cliphist list | head -n 1 | cliphist delete -fi + then + cliphist list | head -n 1 | cliphist delete + fi || + exit 1 +notify-send "mpass" "copied $choice" -- cgit v1.2.3 From 8a2272e0f5f4b43f7ba3fa11f5887880299573b3 Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Sun, 13 Aug 2023 01:53:23 +0200 Subject: [mpass] added notify function --- bin/guiscripts/keyadd | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'bin') diff --git a/bin/guiscripts/keyadd b/bin/guiscripts/keyadd index 1df8896..4613b8f 100755 --- a/bin/guiscripts/keyadd +++ b/bin/guiscripts/keyadd @@ -22,6 +22,13 @@ die () echo "$1" >&2 } +notify () +{ + notify-send -t 1000 "keyadd" "$1" + die "$1" +} + + SSHFOLDER="$HOME/.ssh" if test -z "${key:=$1}" @@ -42,17 +49,19 @@ die "HOST: $HOST" if [ "$1" = "-d" ] then - ssh-add -d - < "$SSHFOLDER"/$key.pub && - notify-send "keyadd" "deleted $key" || - notify-send "keyadd" "could not delete." -elif ! ssh-add -l | grep -q "$(ssh-keygen -lf "$SSHFOLDER"/$key)" + if ssh-add -d - < "$SSHFOLDER"/"$key".pub + then + notify "deleted $key" + else + notify "could not delete." + fi +# check if key is already added +elif ssh-add -l | grep -q "$(ssh-keygen -lf "$SSHFOLDER"/"$key")" then - die "adding: $key" + notify "key already added." +else export PASSWORD="keys/$HOST/ssh/$key" export SSH_ASKPASS="$0" - ssh-add - < "$SSHFOLDER"/$key && - notify-send "keyadd" "added $key" -else - die "key already added." - notify-send "keyadd" "key already added." + ssh-add - < "$SSHFOLDER"/"$key" && + notify "added $key" fi -- cgit v1.2.3 From 396e509716ae5b334f4d588a9b425476770577ea Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Sun, 13 Aug 2023 01:57:30 +0200 Subject: [mpass] added test for connecting to agent --- bin/guiscripts/keyadd | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'bin') diff --git a/bin/guiscripts/keyadd b/bin/guiscripts/keyadd index 4613b8f..e0a1661 100755 --- a/bin/guiscripts/keyadd +++ b/bin/guiscripts/keyadd @@ -31,7 +31,15 @@ notify () SSHFOLDER="$HOME/.ssh" -if test -z "${key:=$1}" +# Test if can connect to ssh-agent +ssh-add -l > /dev/null 2>&1 +if [ $? -gt 1 ] # ignore if there are no identities +then + notify "could not connect to agent." + exit 1 +fi + +if [ -z "${key:=$1}" ] then key="$(find "$SSHFOLDER" -iname "*.pub" | sed "s,$SSHFOLDER/,," | # Clean -- cgit v1.2.3 From f7e3dc17c1692c8099ca4b80814db49d9da2c74c Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Sun, 13 Aug 2023 02:01:02 +0200 Subject: [mpass] cleanup of messages and commands --- bin/guiscripts/keyadd | 20 ++++++++++---------- bin/menuscripts/mpass | 16 ++++++++-------- 2 files changed, 18 insertions(+), 18 deletions(-) (limited to 'bin') diff --git a/bin/guiscripts/keyadd b/bin/guiscripts/keyadd index e0a1661..cb81efe 100755 --- a/bin/guiscripts/keyadd +++ b/bin/guiscripts/keyadd @@ -35,7 +35,7 @@ SSHFOLDER="$HOME/.ssh" ssh-add -l > /dev/null 2>&1 if [ $? -gt 1 ] # ignore if there are no identities then - notify "could not connect to agent." + notify "Could not connect to agent." exit 1 fi @@ -50,26 +50,26 @@ else fi die "key: $key" -test ! -f "$SSHFOLDER/$key" && exit 1 +[ ! -f "$SSHFOLDER/$key" ] && exit 1 -HOST=$(hostnamectl hostname | sed 's/forlure/fl/;s/montecristo/mc/') -die "HOST: $HOST" +HOST=$(hostnamectl hostname) +die "host: $HOST" if [ "$1" = "-d" ] then - if ssh-add -d - < "$SSHFOLDER"/"$key".pub + if ssh-add -q -d - < "$SSHFOLDER"/"$key".pub 2> /dev/null then - notify "deleted $key" + notify "Deleted $key" else - notify "could not delete." + notify "Could not delete." fi # check if key is already added elif ssh-add -l | grep -q "$(ssh-keygen -lf "$SSHFOLDER"/"$key")" then - notify "key already added." + notify "Key already added." else export PASSWORD="keys/$HOST/ssh/$key" export SSH_ASKPASS="$0" - ssh-add - < "$SSHFOLDER"/"$key" && - notify "added $key" + ssh-add -q - < "$SSHFOLDER"/"$key" && + notify "Added $key." fi diff --git a/bin/menuscripts/mpass b/bin/menuscripts/mpass index 8153dc6..0117b97 100755 --- a/bin/menuscripts/mpass +++ b/bin/menuscripts/mpass @@ -16,12 +16,12 @@ do [ "$choice" ] || break file="$file/$choice" done - test -z "$file" && exit 1 -pass show -c "$file" && - if [ -n "$WAYLAND_DISPLAY" ] && cliphist list >/dev/null - then - cliphist list | head -n 1 | cliphist delete - fi || - exit 1 -notify-send "mpass" "copied $choice" + +pass show -c "$file" +test $? -gt 0 && exit 1 + +[ "$WAYLAND_DISPLAY" ] && cliphist list >/dev/null && # on wayland and cliphist is running + cliphist list | head -n 1 | cliphist delete + +notify-send -t 1000 "mpass" "copied $choice" -- cgit v1.2.3 From 818dabae65e67cb52f11623ab1e76ad4c85c19e1 Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Sun, 13 Aug 2023 02:08:33 +0200 Subject: added confirm, trl and wipe scripts! --- bin/extra/confirm | 12 ++++++ bin/extra/trl | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ bin/extra/wipe | 13 ++++++ 3 files changed, 140 insertions(+) create mode 100755 bin/extra/confirm create mode 100755 bin/extra/trl create mode 100755 bin/extra/wipe (limited to 'bin') diff --git a/bin/extra/confirm b/bin/extra/confirm new file mode 100755 index 0000000..116b468 --- /dev/null +++ b/bin/extra/confirm @@ -0,0 +1,12 @@ +#!/bin/sh + +read_char () +{ + old_stty_cfg=$(stty -g 2> /dev/null) + stty raw -echo 2> /dev/null + dd ibs=1 count=1 2> /dev/null + stty $old_stty_cfg 2> /dev/null +} + +>&2 printf "$1 " +read_char | grep -q "[yY]" diff --git a/bin/extra/trl b/bin/extra/trl new file mode 100755 index 0000000..ee42040 --- /dev/null +++ b/bin/extra/trl @@ -0,0 +1,115 @@ +#!/bin/sh + +# prints on stderr +log () { >&2 echo "$@"; } + +help () +{ + >&2 cat <<-EOF + h help + l clear output + q quit + + i invert languages + p select primary + s select secondary + EOF +} +# returns available languages +languages () { + cat <<-EOF + arabic + dutch + french + german + polish + english + portuguese + spanish + romanian + hebrew + swedish + italian + turkish + japanese + ukrainian + korean + chinese + czech + hungarian + danish + persian + greek + slovak + hindi + thai + EOF +} + +# translates a word +# $1: primary language +# $2: secondary language +# $3: word to translate +translate () +{ + curl -s "https://context.reverso.net/translation/$1-$2/$3" \ + --compressed \ + -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/116.0' \ + -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8' \ + -H 'Accept-Language: en-US,en;q=0.5' \ + -H 'Accept-Encoding: gzip, deflate, br' | + pup 'a.link_highlighted em text{}' | + sed 's/.*/\L&/' | + sort | uniq | sed 's/.*/ &/' +} + +# prints the current language +current_language () +{ + log " current: $primary-$secondary" +} + +select_language () +{ + tmp="$(languages | fzf)" + [ "$tmp" ] && [ "$tmp" != "$primary" ] && [ "$tmp" != "$secondary" ] && + eval "$1=\"$tmp\"" + current_language +} + +# set default languages +primary=french +secondary=dutch + + +main () +{ + current_language + while true + do + log -n '>' + read -r prompt + test $? -eq 1 && exit 0 # quit on ctrl-d + case "$prompt" in + q) break ;; + l) clear ;; + i) tmp="$secondary"; secondary="$primary"; primary="$tmp" + current_language ;; + h) help ;; # TODO + p) select_language primary ;; + s) select_language secondary ;; + '') ;; + *) translate "$primary" "$secondary" "$prompt" ;; + esac + done +} + + +if [ "$1" = "--help" ] || [ "$1" = "-h" ] +then + log "usage: trl" + help + exit +fi + +main diff --git a/bin/extra/wipe b/bin/extra/wipe new file mode 100755 index 0000000..ec2abe9 --- /dev/null +++ b/bin/extra/wipe @@ -0,0 +1,13 @@ +#!/bin/sh +[ 0 -eq "$#" ] && >&2 echo 'usage: wipe ' && exit 1 +[ ! -f "$1" ] && [ ! -d "$1" ] && >&2 echo "'$1' not found." && exit 1 + +confirm "sure?" || exit 1 +>&2 printf "\n" + +find "$1" -type f -print0 | + xargs -0I{} shred -uz "{}" && + [ -d "$1" ] && # remove leftovver empty directories + find "$1" | tac | tr '\n' '\0' | + xargs -0I{} rm -d "{}" && + >&2 echo "wiped." -- cgit v1.2.3 From b3f42fec8739d1d23ec6d64ff35c9db022c5adca Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Sun, 13 Aug 2023 20:15:52 +0200 Subject: [googoo] removed functions and updated behaviour removed functions that where unneed as they were only called once, changed behaviour to not implement fzf in goo but in the functions itself, this makes goo easier to implement in other commands. Also ported over the funcitonality of setting the query with the first argument --- bin/common/goo | 7 +------ config/essentials/zsh/functions.zsh | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 13 deletions(-) (limited to 'bin') diff --git a/bin/common/goo b/bin/common/goo index 2a5faad..a56cbaf 100755 --- a/bin/common/goo +++ b/bin/common/goo @@ -15,14 +15,9 @@ VisualParadigm intellij arduino15" -if [ -n "$2" ] -then - [ -d "$2" ] && dest="$2" || opt="-q $2" -fi - for dir in $exclude; do dirs="$dirs -name \"$dir\" -o " done cmd="find ${dest:-$HOME} \(${dirs} -false \) -prune -o -type ${1:-f} -mindepth 1 -print" -eval "$cmd" 2>/dev/null | fzf $opt +eval "$cmd" 2>/dev/null diff --git a/config/essentials/zsh/functions.zsh b/config/essentials/zsh/functions.zsh index 053ce8e..c4999db 100644 --- a/config/essentials/zsh/functions.zsh +++ b/config/essentials/zsh/functions.zsh @@ -39,23 +39,30 @@ nnn() { test -z "$NNNLVL" && /usr/bin/nnn "$@" || exit } ranger() { test -z "$RANGER_LEVEL" && /usr/bin/ranger "$@" || exit } # googoo aliases -ff () { goo f "$1" } -fd () { goo d "$1" } -fdf () { goo f "$1" | xargs -I {} dirname "{}" } +_googoo_fzf_opt () +{ + if [ "$1" ] + then + [ -d "$1" ] && dest="$1" || opt="-q $1" + fi +} o () { - f="$(ff $1)" + _googoo_fzf_opt "$1" + f="$(goo f "dest" | fzf $opt)" test "$1" && shift - test -n "$f" && $EDITOR $@ "$f" + test -f "$f" && $EDITOR $@ "$f" } go () { - d="$(fd $1)" + _googoo_fzf_opt "$1" + d="$(goo d "$dest" | fzf $opt)" test -d "$d" && cd "$d" } ogo () { - d="$(fdf $1)" + _googoo_fzf_opt "$1" + d="$(dirname "$(goo f "$dest")" | fzf $opt)" test -d "$d" && cd "$d" } -- cgit v1.2.3 From 949d2f7025cbfe4db316a3fc13199ac5c82d4b5b Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Sun, 13 Aug 2023 20:18:46 +0200 Subject: [zshrc] use exec and keychain identity Add keychain identity on startup, this is more useful because with suspend I will only type the password once per day. Also it makes adding with keyadd faster. Also use exec to have less processes, don't know if it works though... --- bin/guiscripts/startw | 1 + config/essentials/zsh/.zshrc | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'bin') diff --git a/bin/guiscripts/startw b/bin/guiscripts/startw index 768f401..9b35556 100755 --- a/bin/guiscripts/startw +++ b/bin/guiscripts/startw @@ -1,5 +1,6 @@ #!/bin/sh eval "$(keychain --dir "$XDG_CONFIG_HOME/keychain" --eval --quiet --agents gpg,ssh)" +eval "$(keychain --dir "$XDG_CONFIG_HOME/keychain" --eval --quiet --agents gpg 3A626DD20A32EB2E5DD9CE71CFD9ABC97158CD5D 2> /dev/null)" Hyprland diff --git a/config/essentials/zsh/.zshrc b/config/essentials/zsh/.zshrc index d8675d4..0665533 100644 --- a/config/essentials/zsh/.zshrc +++ b/config/essentials/zsh/.zshrc @@ -5,9 +5,9 @@ then clear if [ "/dev/tty1" = "$TTY" ] then - startw > /dev/null 2>&1 + exec startw > /dev/null 2>&1 else - startx > /dev/null 2>&1 + exec startx > /dev/null 2>&1 fi exit fi -- cgit v1.2.3 From ab67292b4ce728aea904799197e761002832f8c5 Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Sun, 13 Aug 2023 20:37:39 +0200 Subject: [mpass] cleanup of error handling use || instead of test $? -gt 0, because they do the same thing. --- bin/menuscripts/mpass | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'bin') diff --git a/bin/menuscripts/mpass b/bin/menuscripts/mpass index 0117b97..4ecd4bc 100755 --- a/bin/menuscripts/mpass +++ b/bin/menuscripts/mpass @@ -18,10 +18,8 @@ do done test -z "$file" && exit 1 -pass show -c "$file" -test $? -gt 0 && exit 1 +pass show -c "$file" || exit 1 +notify-send -t 1000 "mpass" "copied $choice" [ "$WAYLAND_DISPLAY" ] && cliphist list >/dev/null && # on wayland and cliphist is running cliphist list | head -n 1 | cliphist delete - -notify-send -t 1000 "mpass" "copied $choice" -- cgit v1.2.3 From 22d2c57240e65df482e30fbe684844c6b173aca2 Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Mon, 14 Aug 2023 12:37:09 +0200 Subject: [saf] added load function --- bin/common/saf | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'bin') diff --git a/bin/common/saf b/bin/common/saf index 0c6fbc4..dcc43d5 100755 --- a/bin/common/saf +++ b/bin/common/saf @@ -7,6 +7,15 @@ green="$(printf '\033[32m')" blue="$(printf '\033[34m')" reset="$(printf '\033[0m')" +load () +{ + for time in $(uptime | cut -f3- -d',' | cut -f2 -d':' | tr ',' ' ') + do + percent="$(echo "$time*100/$(nproc)" | bc)" + echo "${percent:-0}%" + done | xargs +} + for file in /etc/os-release /usr/lib/os-release do [ -f "$file" ] && . "$file" && break @@ -19,6 +28,6 @@ SHELL="$(basename "$SHELL")" cat < Date: Mon, 14 Aug 2023 12:37:22 +0200 Subject: [saf] removed unused green color --- bin/common/saf | 1 - 1 file changed, 1 deletion(-) (limited to 'bin') diff --git a/bin/common/saf b/bin/common/saf index dcc43d5..9e31c68 100755 --- a/bin/common/saf +++ b/bin/common/saf @@ -3,7 +3,6 @@ # Simple Ass Fetch by futxlii red="$(printf '\033[31m')" -green="$(printf '\033[32m')" blue="$(printf '\033[34m')" reset="$(printf '\033[0m')" -- cgit v1.2.3 From 0b8685b836fb3cc034857438bf87076fa39af1a1 Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Mon, 14 Aug 2023 12:50:14 +0200 Subject: [saf] remove bc dependency --- bin/common/saf | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'bin') diff --git a/bin/common/saf b/bin/common/saf index 9e31c68..2936346 100755 --- a/bin/common/saf +++ b/bin/common/saf @@ -8,10 +8,11 @@ reset="$(printf '\033[0m')" load () { - for time in $(uptime | cut -f3- -d',' | cut -f2 -d':' | tr ',' ' ') - do - percent="$(echo "$time*100/$(nproc)" | bc)" - echo "${percent:-0}%" + # take everything after 'load average: ' then remove '0.' or '.' or ',' + # from output, this multiplies by hundred, so we can divide an integer + # instead of a fraction (which dash can't do) + for time in $(uptime | sed -e 's/^.*load average://' -e 's/0\?\.\|,//g') + do printf "%s%%\n" "$((time/$(nproc)))" done | xargs } -- cgit v1.2.3 From e1893b1b31503adaa2c2484b57a5d7a4a5d0516c Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Mon, 14 Aug 2023 21:37:08 +0200 Subject: [googoo] fixed destination argument not working --- bin/common/goo | 2 +- config/essentials/zsh/functions.zsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'bin') diff --git a/bin/common/goo b/bin/common/goo index a56cbaf..cfd03ec 100755 --- a/bin/common/goo +++ b/bin/common/goo @@ -18,6 +18,6 @@ arduino15" for dir in $exclude; do dirs="$dirs -name \"$dir\" -o " done -cmd="find ${dest:-$HOME} \(${dirs} -false \) -prune -o -type ${1:-f} -mindepth 1 -print" +cmd="find ${2:-$HOME} \(${dirs} -false \) -prune -o -type ${1:-f} -mindepth 1 -print" eval "$cmd" 2>/dev/null diff --git a/config/essentials/zsh/functions.zsh b/config/essentials/zsh/functions.zsh index 3c5f11f..e0eeb45 100644 --- a/config/essentials/zsh/functions.zsh +++ b/config/essentials/zsh/functions.zsh @@ -49,7 +49,7 @@ _googoo_fzf_opt () o () { _googoo_fzf_opt "$1" - f="$(goo f "dest" | fzf $opt)" + f="$(goo f "$dest" | fzf $opt)" test "$1" && shift test -f "$f" && $EDITOR $@ "$f" } -- cgit v1.2.3 From ece73a892806912ed45f875149065085690d64d4 Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Tue, 15 Aug 2023 16:40:43 +0200 Subject: [y2feed] added support for different links You can now supply a channel id, a link to a channel or a tag, this should work with yt-local and piped as well. --- bin/common/y2feed | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'bin') diff --git a/bin/common/y2feed b/bin/common/y2feed index e30bccf..b55d66b 100755 --- a/bin/common/y2feed +++ b/bin/common/y2feed @@ -1,5 +1,18 @@ #!/bin/sh -echo "url: $1" >&2 -curl -L -s "$1" | - pup 'link[title=RSS] attr{href}' | - tee /dev/stderr + +get_feed() +{ + link="$(curl -L -s "$1" | pup 'link[title=RSS] attr{href}' 2>/dev/null)" + [ "$link" ] && printf "%s\n" "$link" | tee /dev/stderr && exit +} + +[ "$1" ] || exit 1 + +# url is channel +get_feed "$1" + +part="$(echo "$1" | awk -F '/' '{print $NF}')" +# last part is channel id +get_feed "https://www.youtube.com/channel/$part" +# last part is channel tag +get_feed "https://www.youtube.com/$part" -- cgit v1.2.3 From 95926dbc3923e2f4f1a582713c7e6b0fb3fb9e6e Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Tue, 22 Aug 2023 11:52:56 +0200 Subject: [mpdf] refactor and use of commander introduce the use of commander to get rid of if else, also use tee to write to temporary file --- bin/menuscripts/mpdf | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) (limited to 'bin') diff --git a/bin/menuscripts/mpdf b/bin/menuscripts/mpdf index d67fdae..85debfb 100755 --- a/bin/menuscripts/mpdf +++ b/bin/menuscripts/mpdf @@ -1,22 +1,10 @@ #!/bin/sh -if [ "$MENUCMD" = "tofi" ] -then - menucmd="tofi --width 30% --height 30% --matching-algorithm normal --prompt-text pdf:" -elif [ "$MENUCMD" = "dmenu" ] -then - menucmd="dmenu -l 10 -g 1 -x -i -p pdf:" -else - menucmd="fzf" -fi - -tmp="/tmp/dmpdf" -find ${1:-$HOME/docs $HOME/dl} 2> /dev/null | grep -E ".+\.pdf" | sort > "$tmp" -choice="$(sed "s|^$HOME|\~| ; s|\([^/]\)[^/]*/|\1/|g" "$tmp" | - awk '{printf "%s %s\n", NR ":", $0}' | - $menucmd | - grep -o "^[0-9]\+:" | - cut -f 1 -d :)" -test -z "$choice" && exit 1 +tmp="/tmp/mpdf" +choice="$(find ${1:-$HOME/docs $HOME/dl} -iname "*.pdf" 2> /dev/null | sort | + tee "$tmp" | + sed "s|^$HOME|\~| ; s|\([^/]\)[^/]*/|\1/|g" | + commander -x -n)" file="$(sed -n "${choice}p" "$tmp")" +[ -r "$file" ] || exit 1 zathura "$file" & -- cgit v1.2.3 From e68f87e355dab3094bf5195cb51fc79ce6f8569d Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Tue, 22 Aug 2023 12:02:48 +0200 Subject: [mvid] refactor and use commander use tee to write to temp file, use commander instead of if else statement --- bin/menuscripts/mvid | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) (limited to 'bin') diff --git a/bin/menuscripts/mvid b/bin/menuscripts/mvid index ca309fb..09ebab8 100755 --- a/bin/menuscripts/mvid +++ b/bin/menuscripts/mvid @@ -1,27 +1,16 @@ #!/usr/bin/env sh -tmpfile="/tmp/dmvids" +tmp="/tmp/dmvids" dirs="${1:-$HOME/vids $HOME/dl}" -find -L $dirs 2> /dev/null | - grep ".\+\.\(webm\|mp4\|mpeg\|mkv\)$" | - sort > "$tmpfile" -if [ "$MENUCMD" = "tofi" ] -then - menucmd="tofi --width 30% --height 30% --matching-algorithm normal" -elif [ "$MENUCMD" = "dmenu" ] -then - menucmd="dmenu -l 10 -g 1 -x -i" -else - menucmd="fzf" -fi +choice="$(find -L $dirs 2> /dev/null | + grep '^.\+\.\(webm\|mp4\|mpeg\|mkv\)$' | + sort | tee "$tmp" | + sed "s#^$HOME#\~#;s#\([^/]\)[^/]*/#\1/#g" | + commander -n -x)" -choice="$(sed "s|^$HOME|\~| ; s|\([^/]\)[^/]*/|\1/|g" "$tmpfile" | - awk '{printf "%s %s\n", NR ":", $0}' | - $menucmd | - cut -f 1 -d ':')" -test -z "$choice" && - exit 1 +file="$(sed -n "${choice}p" "$tmp")" +[ -r "$file" ] || exit 1 -mpv "$(sed -n "${choice}p" "$tmpfile")" +mpv "$file" -- cgit v1.2.3 From 57650e96e2c3a24d2101b5497c255f21b52d2f92 Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Tue, 22 Aug 2023 22:03:13 +0200 Subject: [mpower] small refactor and added commander --- bin/menuscripts/mpower | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'bin') diff --git a/bin/menuscripts/mpower b/bin/menuscripts/mpower index 443ed54..005c497 100755 --- a/bin/menuscripts/mpower +++ b/bin/menuscripts/mpower @@ -1,14 +1,7 @@ #!/bin/sh -if [ "$MENUCMD" = "tofi" ] -then - menucmd="tofi --width 10% --height 13% --padding-left 2%" -elif [ "$MENUCMD" = "dmenu" ] -then - menucmd="dmenu -g 2 -l 2" -else - menucmd="fzf" -fi +choice="$(printf 'poweroff +suspend +hibernate +reboot' | commander -c -d)" -choices="poweroff\nreboot\nhibernate\nsuspend" -choice="$(printf "$choices" | $menucmd)" -test -z "$choice" || systemctl "$choice" +[ "$choice" ] && systemctl "$choice" -- cgit v1.2.3 From dccf53c0d83973623e0d4c3f2550471232cf22b4 Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Tue, 22 Aug 2023 22:25:53 +0200 Subject: [goo] search in pwd by default --- bin/common/goo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bin') diff --git a/bin/common/goo b/bin/common/goo index cfd03ec..cb7a8b6 100755 --- a/bin/common/goo +++ b/bin/common/goo @@ -18,6 +18,6 @@ arduino15" for dir in $exclude; do dirs="$dirs -name \"$dir\" -o " done -cmd="find ${2:-$HOME} \(${dirs} -false \) -prune -o -type ${1:-f} -mindepth 1 -print" +cmd="find ${2:-.} \(${dirs} -false \) -prune -o -type ${1:-f} -mindepth 1 -print" eval "$cmd" 2>/dev/null -- cgit v1.2.3 From 7ab95433e2d80ba03db7667795e72d398b9d2a7b Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Tue, 22 Aug 2023 22:31:08 +0200 Subject: [mpower] added extra newline --- bin/menuscripts/mpower | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'bin') diff --git a/bin/menuscripts/mpower b/bin/menuscripts/mpower index 005c497..3b66824 100755 --- a/bin/menuscripts/mpower +++ b/bin/menuscripts/mpower @@ -2,6 +2,7 @@ choice="$(printf 'poweroff suspend hibernate -reboot' | commander -c -d)" +reboot +' | commander -c -d)" [ "$choice" ] && systemctl "$choice" -- cgit v1.2.3 From 8b9e93321bfd229b8a29fdd1fc60de670e16636d Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Thu, 24 Aug 2023 21:11:27 +0200 Subject: [menuscripts] use 'commander' in menuscripts --- bin/menuscripts/mapimg | 13 ++----------- bin/menuscripts/mcurs | 25 +++++++------------------ bin/menuscripts/mdsktp | 21 ++++----------------- bin/menuscripts/memoji | 21 ++++++--------------- bin/menuscripts/mhelp | 23 ++++++----------------- bin/menuscripts/mmpcvol | 20 +++++--------------- bin/menuscripts/mpass | 32 +++++++++++++++++--------------- bin/menuscripts/mpassgen | 45 ++++++++++----------------------------------- bin/menuscripts/mplay | 20 +++++--------------- bin/menuscripts/mvid | 2 +- 10 files changed, 63 insertions(+), 159 deletions(-) (limited to 'bin') diff --git a/bin/menuscripts/mapimg b/bin/menuscripts/mapimg index 151b8d0..a959d46 100755 --- a/bin/menuscripts/mapimg +++ b/bin/menuscripts/mapimg @@ -1,17 +1,8 @@ #!/bin/sh -if [ -z "$MENUCMD" ] -then - menucmd="fzf" -elif [ "$MENUCMD" = "tofi" ] -then - menucmd='tofi --width 700 --height 300 --prompt-text Appimage:' -else - menucmd="dmenu -x -l 10 -g 1 -p Appimage:" -fi - dest="$XDG_DATA_HOME"/appimages appimage="$(find "$dest" -type f -printf "%f\n" | sed 's/\.[Aa]pp[Ii]mage$//g' | - $menucmd)" + commander -x -l -p "Appimage:")" +[ "$appimage" ] || exit 1 setsid "$dest/${appimage:-NOSEL}"* diff --git a/bin/menuscripts/mcurs b/bin/menuscripts/mcurs index 32f5525..4349e0b 100755 --- a/bin/menuscripts/mcurs +++ b/bin/menuscripts/mcurs @@ -1,22 +1,11 @@ #!/bin/sh -if [ "$MENUCMD" = "tofi" ] -then - menucmd="tofi --width 30% --height 20% --padding-left 2% --matching-algorithm normal" -elif [ "$MENUCMD" = "dmenu" ] -then - menucmd="dmenu -l 10 -g 1 -x -i" -else - menucmd="fzf" -fi - # requirements -which $MENUCMD firefox > /dev/null || - exit 1 +which "$BROWSER" > /dev/null || exit 1 + +choice="$(find "${1:-$HOME/docs/school}" | + grep -i "cursus/index.html" 2> /dev/null | + sed "s;$HOME;~;" | commander -x -d -c)" +[ "$choice" ] && exit 1 -choice="$(find ${1:-$HOME/docs/school} | - grep "Cursus/index.html" 2> /dev/null | - sed "s;$HOME;~;" | - $menucmd)" -test -z "$choice" && exit 1 -firefox "$choice" +$BROWSER "$choice" diff --git a/bin/menuscripts/mdsktp b/bin/menuscripts/mdsktp index a48aca6..f07fb7b 100755 --- a/bin/menuscripts/mdsktp +++ b/bin/menuscripts/mdsktp @@ -1,21 +1,8 @@ #!/bin/sh # Searches through .desktop files and prompt to launch them via dmenu -if [ "$MENUCMD" = "tofi" ] -then - menucmd="tofi" -elif [ "$MENUCMD" = "dmenu" ] -then - menucmd="dmenu -g 1 -i" -else - menucmd="fzf" -fi -choice="$(find ~/.local/share/applications \ - -maxdepth 1 \ - -type f \ - -not -iname "wine-extension*" -a -iname "*.desktop" \ - -printf "%f\n" | - cut -d. -f1 | - $menucmd)" -test -z "$choice" && exit 1 +choice="$(find ~/.local/share/applications -maxdepth 1 -type f -not -iname "wine-extension*" | + awk '/\/[^.\/]+\.desktop/ {print $(NF-1)}' | + commander -s -d -x -c)" +[ "$choice" ] || exit 1 gtk-launch "$choice" diff --git a/bin/menuscripts/memoji b/bin/menuscripts/memoji index d051ad8..9c45950 100755 --- a/bin/menuscripts/memoji +++ b/bin/menuscripts/memoji @@ -7,36 +7,27 @@ if [ "$WAYLAND_DISPLAY" ] then - copycmd="wl-copy" + alias copycmd="wl-copy" else - copycmd="xclip -sel c" -fi -if [ "$MENUCMD" = "tofi" ] -then - menucmd="tofi --width 30% --height 30% --matching-algorithm normal --prompt-text Emoji:" -elif [ "$MENUCMD" = "dmenu" ] -then - menucmd="dmenu -l 20 -g 1 -x -i -p Emoji:" -else - menucmd="fzf --prompt Emoji:" + alias copycmd="xclip -sel c" fi set -e case "$1" in "list") data=$(sed '0,/^__DATA__$/d' "$0") - echo -n "$data" + printf "%s" "$data" ;; "copy") input=$(tee | cut -f 1 -d ' ') - if [ ! -z "$input" ] + if [ "$input" ] then notify-send "dmemoji" "$input copied!" - echo -n "$input" | $copycmd + printf "%s" "$input" | copycmd fi ;; "") - sh $0 list | $menucmd | sh $0 copy + sh "$0" list | commander -p "Emoji:" -l -x | sh "$0" copy ;; esac diff --git a/bin/menuscripts/mhelp b/bin/menuscripts/mhelp index 5963a88..339d6bf 100755 --- a/bin/menuscripts/mhelp +++ b/bin/menuscripts/mhelp @@ -1,29 +1,18 @@ #!/usr/bin/env sh -if [ "$MENUCMD" = "tofi" ] -then - program="$(tofi-run --prompt-text "program: ")" - menucmd="tofi --width 50% --height 30% --matching-algorithm normal --prompt-text $program:" -elif [ "$MENUCMD" = "dmenu" ] -then - program="$(dmenu_path | dmenu -l 4 -g 5 -p "program:")" - menucmd="dmenu -l 20 -g 1 -x -i -p $program:" -else - program="$(dmenu_path | fzf)" - menucmd="fzf" -fi +program="$(commander -r -c -d)" -test -z "$program" && exit 1 +[ "$program" ] || exit 1 -option="$($program --help | +option="$("$program" --help | # Parse options grep "^ *-[-a-zA-Z0-9]* " | tr -s ' ' | sort | uniq | column -l 2 -t | - $menucmd | + commander -l -x -c -d | awk '{print $1}')" -test -z "$option" && exit 1 +[ "$option" ] || exit 1 -setsid $program $option +setsid "$program" "$option" diff --git a/bin/menuscripts/mmpcvol b/bin/menuscripts/mmpcvol index 0f36e18..239dec3 100755 --- a/bin/menuscripts/mmpcvol +++ b/bin/menuscripts/mmpcvol @@ -1,23 +1,13 @@ #!/bin/sh -if [ "$MENUCMD" = "tofi" ] -then - menucmd="tofi --width 5% --height 10% --prompt-text" -elif [ "$MENUCMD" = "dmenu" ] -then - menucmd="dmenu -g 2 -l 1 -p" -else - menucmd="fzf --prompt" -fi - while true do volume="$(mpc volume | awk '{print $2}' | cut -f1 -d'%')" - choice="$(echo "plus\nmin" | - $menucmd "$volume" | + choice="$(printf "plus\nmin\n" | + commander -d -c -p "$volume" | sed 's/plus/+/;s/min/-/')" - test -z "$choice" && break - nb="$($menucmd "$volume$choice" < /dev/null)" - test -z "$nb" && break + [ "$choice" ] || break + nb="$(commander -c -p "$volume$choice" -i)" + [ "$nb" ] || break mpc volume "$choice$nb" done diff --git a/bin/menuscripts/mpass b/bin/menuscripts/mpass index 4ecd4bc..8d5f4eb 100755 --- a/bin/menuscripts/mpass +++ b/bin/menuscripts/mpass @@ -1,25 +1,27 @@ #!/usr/bin/env sh store="${PASSWORD_STORE_DIR:-$HOME/.password-store}" -lscmd="ls --group-directories-first" -if [ "$MENUCMD" = "tofi" ] -then - menucmd="tofi --prompt pass:" -elif [ "$MENUCMD" = "dmenu" ] -then - menucmd="dmenu -l 4 -g 2 -i -p pass:" -else - menucmd="fzf --prompt pass:" -fi + +# list passwords, group directories first +list_pswds() +{ + find "$1" \ + -maxdepth 1 -mindepth 1 \ + -not -name '.*' -type d -printf "%y\t%f\n" -o \ + -not -name '.*' -not -type d -printf "%y\t%f\n" | + sort -k1 -k2 | + cut -f 2 | sed 's/\.gpg$//' +} + while [ -d "$store/$file" ] do - choice="$($lscmd "$store/$file" | sed 's/\.gpg$//'| $menucmd)" - [ "$choice" ] || break - file="$file/$choice" + choice="$(list_pswds "$store/$file" | commander -c -d)" + [ "$choice" ] || exit 1 + [ -z "$file" ] && file="$choice" || file="$file/$choice" done -test -z "$file" && exit 1 +[ "$file" ] || exit 1 pass show -c "$file" || exit 1 -notify-send -t 1000 "mpass" "copied $choice" +notify-send -t 1000 "mpass" "copied $file" [ "$WAYLAND_DISPLAY" ] && cliphist list >/dev/null && # on wayland and cliphist is running cliphist list | head -n 1 | cliphist delete diff --git a/bin/menuscripts/mpassgen b/bin/menuscripts/mpassgen index 8384542..51b9bc4 100755 --- a/bin/menuscripts/mpassgen +++ b/bin/menuscripts/mpassgen @@ -1,46 +1,21 @@ #!/usr/bin/env sh -input () -{ - # menu prompt for output - if [ "$MENUCMD" = "tofi" ] - then - inp="$(tofi --prompt-text "$1 " &2 - read inp - fi - echo $inp -} -# menu select long -if [ "$MENUCMD" = "tofi" ] -then - menucmd="tofi --prompt login:" -elif [ "$MENUCMD" = "dmenu" ] -then - menucmd="dmenu -l 10 -g 1 -x -i -p login:" -else - menucmd="fzf" -fi +input () { commander -c -i -p "$1"; } -choice="$(echo "multiline\nsingle" | $MENUCMD)" -test -z "${choice}" && exit 1 +choice="$(printf "multiline\nsingle\n" | commander -c -d)" +[ "$choice" ] || exit 1 password="$(input "name:")" -test -z "${password}" && exit 1 +[ "$password" ] || exit 1 -if [ "${choice}" = "multiline" ] +if [ "$choice" = "multiline" ] then - login="$(ls -1 ${PASSWORD_STORE_DIR:=$HOME/.password-store}/e-mails | - sed 's/\.gpg$//' | - $menucmd)" - test -z "${login}" && exit 1 + login="$(find "${PASSWORD_STORE_DIR:=$HOME/.password-store}"/e-mails -type f -maxdepth 1 -iname "*.gpg" -printf "%f\n" | + sed 's/\.gpg$//' | commander -c -d -p 'login:')" + [ "$login" ] || exit 1 url="$(input "url:")" - test -z "${url}" && exit 1 - echo "${password}\nlogin: ${login}\nurl: ${url}" | + [ "$url" ] || exit 1 + printf "%s\nlogin: %s\nurl: %s\n" "${password}" "${login}" "${url}" | pass insert -mf "${password}" pass generate -ci "${password}" else diff --git a/bin/menuscripts/mplay b/bin/menuscripts/mplay index 08fcc46..e4fca54 100755 --- a/bin/menuscripts/mplay +++ b/bin/menuscripts/mplay @@ -1,16 +1,6 @@ #!/bin/sh -# menu select long -if [ "$MENUCMD" = "tofi" ] -then - menucmd="tofi --width 50% --height 30% --matching-algorithm normal" -elif [ "$MENUCMD" = "dmenu" ] -then - menucmd="dmenu -l 10 -g 1 -x -i" -else - menucmd="fzf" -fi -choice="$(mpc listall | $menucmd)" -test -z "$choice" && - exit 1 -mpc insert "$choice" && - mpc next +choice="$(mpc listall | commander -c -l -d -x)" +[ "$choice" ] || exit 1 +mpc insert "$choice" || exit 1 +mpc next 2> /dev/null +mpc play 2> /dev/null diff --git a/bin/menuscripts/mvid b/bin/menuscripts/mvid index 09ebab8..85187cb 100755 --- a/bin/menuscripts/mvid +++ b/bin/menuscripts/mvid @@ -8,7 +8,7 @@ choice="$(find -L $dirs 2> /dev/null | grep '^.\+\.\(webm\|mp4\|mpeg\|mkv\)$' | sort | tee "$tmp" | sed "s#^$HOME#\~#;s#\([^/]\)[^/]*/#\1/#g" | - commander -n -x)" + commander -d -n -x)" file="$(sed -n "${choice}p" "$tmp")" [ -r "$file" ] || exit 1 -- cgit v1.2.3 From f4fcf0a66c6d427767d6ea71a64e710964e7570c Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Fri, 25 Aug 2023 00:30:57 +0200 Subject: [commander] added commander! --- bin/menuscripts/commander | 313 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 313 insertions(+) create mode 100755 bin/menuscripts/commander (limited to 'bin') diff --git a/bin/menuscripts/commander b/bin/menuscripts/commander new file mode 100755 index 0000000..028e8a7 --- /dev/null +++ b/bin/menuscripts/commander @@ -0,0 +1,313 @@ +#!/bin/sh + +# An attempt to unify usage of multiple launchers. +# MENUCMD must be set to the name of the lancher +# +# look at the last line to understand how it works + +tmp="$(mktemp -u)" +export menuopts="" +TOFIRC="$HOME/.config/tofi/config" + +options=' +horizontal +center +input +instant +dynamic +long +prompt +numbered +prefix' + +cleanup() { rm -f "$tmp"; } +logn() { >&2 printf '%s\n' "$@"; } + +run() { + IFS=: + set -f + find -L $PATH -type f -printf "%f\n" 2> /dev/null | sort -u +} + +help() { + cat <<-EOF + Usage: commander OPTIONS... + + An attempt to regroup multiple launchers into one, + it detects the value of the MENUCMD variable + + try: + MENUCMD=tofi commander < /etc/passwd + + Options: + -h Display items horizontally + -c Display centered + -i Take an input and return it to stdout + -d Adjust size and style dynamically + -p ARG Prompt user with the specified argument + -l Display in long list format + -n Output the number of matches + -r Select an executable from PATH + -s Invert instant select on single match + -x Invert prefix matching + EOF +} + +add_option() { menuopts="$menuopts $*"; } +get_prop() { awk -F '=' "/$1 *=*/ {print \$2}" "$TOFIRC"; } + + +trap cleanup EXIT + +# Helper functions +case "$MENUCMD" in + "tofi") + # $1: items count + get_height() + { + font_size="$(get_prop "font-size")" + padding_top="$(get_prop "padding-top")" + padding_bottom="$(get_prop "padding-bottom")" + + printf "%s" "$(( + font_size*2 + padding_top + padding_bottom + 2 + + ($1)*(font_size*2 - 2) + ))" + + } + # $1: items length + get_width() + { + font_size="$(get_prop "font-size")" + padding_left="$(get_prop "padding-left")" + padding_right="$(get_prop "padding-right")" + printf "%s" "$(($1*(font_size-2) + 2 + padding_left + padding_right))" + } ;; + "dmenu") ;; + *) ;; +esac + + +main() +{ + # shellcheck disable=SC2317 + case "$MENUCMD" in + "tofi") + center() { add_option "--anchor=center --width=20%"; } + + horizontal() { + add_option "--horizontal=true --height=32" + add_option "--result-spacing=12" + add_option "--selection-background=#88c0d0" + add_option "--selection-background-padding=6,4" + add_option "--padding-top=0 --padding-bottom=0" + add_option "--margin-top=4" + } + + dynamic() { + pre_cmd() + { + max_height="$(get_height 8)" + max_width="$(get_width 48)" + + tee "$tmp" + + items_count="$(wc -l < "$tmp")" + items_length="$(wc -L < "$tmp")" + + if [ "$long" -ne 1 ] + then + height="$(get_height "$items_count")" + [ "$height" -gt "$max_height" ] && height="$max_height" + add_option "--height=$height" + fi + + width="$(get_width "$items_length")" + [ "$width" -gt "$max_width" ] && width="$max_width" + + + if [ "$prompt" -eq 1 ] + then + prompt_width="$(printf "%s" "$prompt_arg" | wc -c)" + width="$((width + $(get_width "$prompt_width")))" + fi + + add_option "--width=$width" + } + } + + long() { add_option "--width=100% --height=$(get_height 20)"; } + + input() { + add_option "--height=$(get_height 0) --width=$(get_width 24)" + pre_filter() { cat /dev/null; } + } + + prefix() { add_option '--matching-algorithm=normal'; } + + instant() { add_option "--auto-accept-single=false"; } + + prompt() { add_option '--prompt-text' "$prompt_arg"; } + + numbered() { + pre_filter() { awk '{print NR, $0}'; } + post_filter() { awk '{print $1}'; } + } + + menucmd() { tofi "$@"; } + ;; + + "dmenu") + horizontal() { add_option "-l 0"; } + + center() { add_option "-c"; } + + long() { add_option "-l 20 -g 1"; } + + input() { + pre_filter() { cat /dev/null; } + } + + dynamic() { + pre_cmd() + { + tee "$tmp" + items_count="$(wc -l < "$tmp")" + number="$items_count" + + for i in $(seq $((number/2))) + do [ "$((number%i))" -eq 0 ] && factors="$i $factors" + done + + min_diff=9999999999 + for factor in $factors + do + quotient="$((number/factor))" + diff=$((quotient - factor)) + if [ "$diff" -ge 0 ] && [ "$diff" -lt "$min_diff" ] + then + columns="$factor" + rows="$quotient" + min_diff="$diff" + fi + done + + add_option "-g $columns" + add_option "-l $rows" + } + } + + instant() { add_option "-n"; } + + prefix() { add_option '-x'; } + + prompt() { add_option '-p' "$prompt_arg"; } + + numbered() { add_option "-px"; } + + menucmd() { dmenu "$@"; } + ;; + + *) + center() { :; } + + horizontal() { :; } + + dynamic() { :; } + + long() { :; } + + input() { + pre_filter() { cat /dev/null; } + add_option '--print-query' + } + + prefix() { :; } + + prompt() { add_option "--prompt" "$prompt_arg"; } + + numbered() { + pre_filter() { awk '{print NR, $0}'; } + add_option '--with-nth' '2..' + post_filter() { awk '{print $1}'; } + } + + menucmd() { fzf "$@"; } + ;; + esac + + for option in $options + do eval "$option=0" + done + + while getopts ":cdhilop:nrsx" opt + do + # shellcheck disable=SC2034 + case $opt in + + # display horizontal + h) horizontal=1 ;; + # display centered + c) center=1 ;; + # take an input and return it on stdout + i) input=1 ;; + # adjust size and style dynamically + d) dynamic=1 ;; + p) prompt=1; prompt_arg="$OPTARG";; + # long list format + l) long=1 ;; + # output number of match + n) numbered=1 ;; + # select an executable from PATH + r) shift + run | $0 "$@" + exit ;; + # invert instant select on single match + s) instant=1 ;; + # invert prefix matching + x) prefix=1 ;; + + :) + logn "Option '-$OPTARG' requires an argument" + help + exit 1 ;; + ?) + logn "Invalid option: -$OPTARG" + help + exit 1 ;; + esac + done + + + # conflicts + [ "$input" -eq 1 ] && [ "$dynamic" -eq 1 ] && logn "conflicting options." && help && exit 1 + + # quit if stdin is empty + [ -t 0 ] && [ "$input" -eq 0 ] && logn "Stdin is empty." && help && exit 1 + + # call options + for option in $options + do eval "test \"\$$option\" -eq 1" && $option + done + + command -v pre_filter > /dev/null || pre_filter() { cat; } + command -v post_filter > /dev/null || post_filter() { cat; } + + which "${MENUCMD:-fzf}" > /dev/null || exit 1 + + + + if command -v pre_cmd > /dev/null + then + pre_cmd > "$tmp" + >&2 printf "menuopts: %s\n" "$menuopts" + # shellcheck disable=SC2086 + pre_filter < "$tmp" | menucmd $menuopts | post_filter + else + >&2 printf "menuopts: %s\n" "$menuopts" + # shellcheck disable=SC2086 + pre_filter | menucmd $menuopts | post_filter + fi +} + +main "$@" -- cgit v1.2.3 From cf31b107005e5342cd181277be35f570247a70f6 Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Sun, 27 Aug 2023 12:50:54 +0200 Subject: [commander] added verbose option --- bin/menuscripts/commander | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'bin') diff --git a/bin/menuscripts/commander b/bin/menuscripts/commander index 028e8a7..78a27c9 100755 --- a/bin/menuscripts/commander +++ b/bin/menuscripts/commander @@ -21,7 +21,12 @@ numbered prefix' cleanup() { rm -f "$tmp"; } -logn() { >&2 printf '%s\n' "$@"; } + +logn() +{ + [ "${log_on:=0}" -eq 0 ] && return + >&2 printf '%s\n' "$@" +} run() { IFS=: @@ -240,7 +245,7 @@ main() do eval "$option=0" done - while getopts ":cdhilop:nrsx" opt + while getopts ":cdhilop:nrsxv" opt do # shellcheck disable=SC2034 case $opt in @@ -266,6 +271,7 @@ main() s) instant=1 ;; # invert prefix matching x) prefix=1 ;; + v) log_on=1 ;; :) logn "Option '-$OPTARG' requires an argument" @@ -300,11 +306,11 @@ main() if command -v pre_cmd > /dev/null then pre_cmd > "$tmp" - >&2 printf "menuopts: %s\n" "$menuopts" + logn "menuopts: $menuopts" # shellcheck disable=SC2086 pre_filter < "$tmp" | menucmd $menuopts | post_filter else - >&2 printf "menuopts: %s\n" "$menuopts" + logn "menuopts: $menuopts" # shellcheck disable=SC2086 pre_filter | menucmd $menuopts | post_filter fi -- cgit v1.2.3 From 2877c527c52909d5735e9b2c1c7905bb22bc4d87 Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Sun, 27 Aug 2023 12:51:13 +0200 Subject: [commander] added placeholder instant function --- bin/menuscripts/commander | 2 ++ 1 file changed, 2 insertions(+) (limited to 'bin') diff --git a/bin/menuscripts/commander b/bin/menuscripts/commander index 78a27c9..ff58a56 100755 --- a/bin/menuscripts/commander +++ b/bin/menuscripts/commander @@ -227,6 +227,8 @@ main() add_option '--print-query' } + instant() { :; } + prefix() { :; } prompt() { add_option "--prompt" "$prompt_arg"; } -- cgit v1.2.3