From d453810eaa897ab710d0054763136e7c43865ce5 Mon Sep 17 00:00:00 2001 From: urosm Date: Sat, 12 Aug 2023 01:23:53 +0200 Subject: [PATCH] add scripts --- .local/bin/fuzzel_find_file.sh | 12 ++++++++++++ .local/bin/fuzzel_mount.sh | 35 ++++++++++++++++++++++++++++++++++ .local/bin/fuzzel_open_file.sh | 22 +++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100755 .local/bin/fuzzel_find_file.sh create mode 100755 .local/bin/fuzzel_mount.sh create mode 100755 .local/bin/fuzzel_open_file.sh diff --git a/.local/bin/fuzzel_find_file.sh b/.local/bin/fuzzel_find_file.sh new file mode 100755 index 0000000..38586e0 --- /dev/null +++ b/.local/bin/fuzzel_find_file.sh @@ -0,0 +1,12 @@ +#!/usr/bin/sh +# +# fuzzel_find_file.sh +# +# Search for file and open it. Requires fuzzel and find. + +pattern=$(fuzzel --dmenu --prompt "$ find . -type f ") || exit +selection=$(find . -type f -iname "$pattern" | fuzzel --dmenu --prompt "$ open ") + +if [ -n "$selection" ]; then + exec open "$selection" +fi diff --git a/.local/bin/fuzzel_mount.sh b/.local/bin/fuzzel_mount.sh new file mode 100755 index 0000000..eb339ce --- /dev/null +++ b/.local/bin/fuzzel_mount.sh @@ -0,0 +1,35 @@ +#!/usr/bin/sh +# +# fuzzel_mount.sh +# +# Mount devices. Requires fuzzel and udisksctl. + +LSBLK_PART_TYPE="part" +LSBLK_LIST=$(lsblk -Ppo name,type,mountpoint) + +while read -r line; do + while read -r keyval; do + eval "$keyval" + done <<- EOF + $line + EOF + + expr "$NAME" : "/dev/sda." && continue + [ "$TYPE" = "$LSBLK_PART_TYPE" ] || continue + + if [ -n "$MOUNTPOINT" ]; then + option_list=$(printf %s%s\\n "$option_list" "udisksctl unmount -b $NAME") + else + option_list=$(printf %s%s\\n "$option_list" "udisksctl mount -b $NAME") + fi + +done <<- EOF + $LSBLK_LIST + EOF + +selection=$(printf %s "$option_list" | fuzzel --dmenu --prompt "$ ") + +if [ -n "$selection" ]; then + # TODO: notification and error reporting + exec $selection +fi diff --git a/.local/bin/fuzzel_open_file.sh b/.local/bin/fuzzel_open_file.sh new file mode 100755 index 0000000..8ee0979 --- /dev/null +++ b/.local/bin/fuzzel_open_file.sh @@ -0,0 +1,22 @@ +#!/usr/bin/sh +# +# fuzzel_open_file.sh DIR +# +# Open file or terminal in current directory. Requires fuzzel and +# xdg-open. + +DIR=${1:-$HOME} +cd "$DIR" || exit 1 +DIR="$(pwd)" + +selection=$(ls --group-directories-first -a1v | fuzzel --dmenu --prompt "$ open $DIR/") + +if [ -n "$selection" ]; then + if [ "$selection" = "." ]; then + exec $TERMINAL -D "$DIR" + elif [ -d "$DIR/$selection" ]; then + exec $0 "$DIR/$selection" + elif [ -f "$DIR/$selection" ]; then + exec open "$DIR/$selection" + fi +fi