From b99824da0fa9dd9dbc0409b8e6fc713827eb9a22 Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Tue, 4 Apr 2023 20:16:50 -0400 Subject: [PATCH] Add a little knock-off rofi. --- fake_home/.sofi.sh | 93 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100755 fake_home/.sofi.sh diff --git a/fake_home/.sofi.sh b/fake_home/.sofi.sh new file mode 100755 index 0000000..045fabe --- /dev/null +++ b/fake_home/.sofi.sh @@ -0,0 +1,93 @@ +#!/bin/bash + +# Open search window or raise existing one +if [[ "$1" == "--launch" ]]; then + if existing="$(xdotool search active-sofi-window)"; then + xdotool windowraise "$existing" + else + xfce4-terminal --role='active-sofi-window' --hide-borders -e 'bash -c "/home/sage/.sofi.sh"' + # xterm -e 'bash -c "/home/sage/.sofi.sh"' + fi + exit $? +fi + +windows() { + xprop -root _NET_CLIENT_LIST | + pcregrep -o1 '# (.*)' | + sed 's/, /\n/g' | + xargs -I{} -n1 xprop -id {} _NET_WM_NAME | + grep -v '"Desktop"\|"xfce4-panel"' | + sed 's/_NET_WM_NAME(UTF8_STRING) = "/win /' | sed 's/"$//' +} + +app_locations="/usr/share/applications $HOME/.local/share/applications " + +read_apps() { + cat ~/.sofi-app-cache + # shellcheck disable=SC2086 + nohup find $app_locations -name '*.desktop' -exec grep '^Name=' {} \; | + grep -v 'Firetools' | + sed 's/Name=/app /' > ~/.sofi-app-cache & +} + +open_app() { + app="$(echo "$1" | cut -c 5-)" + # shellcheck disable=SC2086 + find $app_locations -name '*.desktop' | while read -r f; do + if grep "Name=$app" "$f" &> /dev/null; then + nohup xdg-open "$f" &> /dev/null & + sleep 1 + return + fi + done +} + +file_locations="$HOME/Documents $HOME/Downloads" +list_files() { + find $file_locations -maxdepth 1 -not -name '.*' | + sed "s@$HOME@\~@" | + sed 's/^/fil /' +} + +paste_emoji() { + emoji="$(echo -n "$1" | cut -c 5- | sed 's/ .*//')" + nohup xclip -selection clipboard <(echo -n $emoji) &> /dev/null & +} + +# cat \ +# <(windows) \ +# <($HOME/.rofi-list-git-repos.py --no-icon) \ +# <(read_apps) \ +# <(list_files) \ +# $HOME/.emojis +# exit 1 + +choice="$(cat \ + <(windows) \ + <("$HOME/.rofi-list-git-repos.py" --no-icon) \ + <(read_apps) \ + <(list_files) \ + "$HOME/.emojis" \ + | fzf)" + +case $choice in + git*) + nohup "$HOME/.rofi-list-git-repos.py" "$choice" &> /dev/null & + ;; + win*) + wmctrl -i -R "$(xwininfo -root -tree | + grep "$(echo "$choice" | cut -c 5-)" | + awk '{ print $1 }' | + sed 's/0x/0x00/')" + ;; + app*) + open_app "$choice" + ;; + emj*) + paste_emoji "$choice" + ;; + fil*) + nohup xdg-open "$(echo $choice | cut -c 5- | sed "s@~@$HOME@")" &> /dev/null & + ;; +esac +sleep 0.1