More consistent backgrounding in sofi.sh

A few simple vars for shared values
This commit is contained in:
Sage Vaillancourt 2023-04-28 16:09:04 -04:00
parent ca2c34514d
commit 3d2fb260c3
1 changed files with 34 additions and 23 deletions

View File

@ -1,41 +1,51 @@
#!/bin/bash #!/bin/bash
WINDOW_NAME="active-sofi-window" WINDOW_NAME="active-sofi-window"
CACHE_FILE="$HOME/.app-cache-sofi"
IGNORED_APPS="Firetools|cmatrix"
APP_LOCATIONS="/usr/share/applications $HOME/.local/share/applications "
FILE_LOCATIONS="$HOME/Documents $HOME/Downloads"
! [[ "$XDG_SESSION_TYPE" = "x11" ]]
IS_X11="$?"
# Open search window or raise existing one # Open search window or raise existing one
if [[ "$1" == "--launch" ]]; then if [[ "$1" == "--launch" ]]; then
if existing="$(xdotool search $WINDOW_NAME)"; then if (($IS_X11)) && existing="$(xdotool search $WINDOW_NAME)"; then
xdotool windowraise "$existing" xdotool windowraise "$existing"
else else
xfce4-terminal --role="$WINDOW_NAME" --title="$WINDOW_NAME" --startup-id="$WINDOW_NAME" -e "bash -c '$HOME/.sofi.sh'" # xfce4-terminal --role="$WINDOW_NAME" --title="$WINDOW_NAME" --startup-id="$WINDOW_NAME" -e "bash -c '$HOME/.sofi.sh'"
# xterm -e "bash -c '$HOME/.sofi.sh'" xterm -fa 'Monospaced' -fs 10 -e "bash -c '$HOME/.sofi.sh'"
# st -e bash -c '$HOME/.sofi.sh'"
fi fi
exit $? exit $?
fi fi
windows() { windows() {
if ! (($IS_X11)); then
return
fi
xprop -root _NET_CLIENT_LIST | xprop -root _NET_CLIENT_LIST |
pcregrep -o1 '# (.*)' | pcregrep -o1 '# (.*)' |
sed 's/, /\n/g' | sed 's/, /\n/g' |
xargs -I{} -n1 xprop -id {} _NET_WM_NAME | xargs -I {} -n1 xprop -id {} _NET_WM_NAME |
grep -v '"Desktop"\|"xfce4-panel"' | grep -v '"Desktop"\|"xfce4-panel"' |
sed 's/_NET_WM_NAME(UTF8_STRING) = "/win /' | sed 's/"$//' sed 's/_NET_WM_NAME(UTF8_STRING) = "/win /' | sed 's/"$//'
} }
app_locations="/usr/share/applications $HOME/.local/share/applications "
read_apps() { read_apps() {
cat ~/.sofi-app-cache cat "$CACHE_FILE"
# shellcheck disable=SC2086 # shellcheck disable=SC2086
nohup find $app_locations -name '*.desktop' -exec grep '^Name=' {} \; | nohup find $APP_LOCATIONS -name '*.desktop' -exec grep '^Name=' {} \; |
grep -v 'Firetools' | egrep -iv "$IGNORED_APPS" |
sed 's/Name=/app /' > ~/.sofi-app-cache & sed 's/Name=/app /' > "$CACHE_FILE" &
} }
open_app() { open_app() {
app="$(echo "$1" | cut -c 5-)" app="$(echo "$1" | cut -c 5-)"
# shellcheck disable=SC2086 # shellcheck disable=SC2086
find $app_locations -name '*.desktop' | while read -r f; do find $APP_LOCATIONS -name '*.desktop' | while read -r f; do
if grep "Name=$app" "$f" &> /dev/null; then if grep "Name=$app" "$f" &> /dev/null; then
setsid exo-open "$f" >/dev/null 2>&1 </dev/null & setsid exo-open "$f" >/dev/null 2>&1 </dev/null &
return return
@ -43,9 +53,8 @@ open_app() {
done done
} }
file_locations="$HOME/Documents $HOME/Downloads"
list_files() { list_files() {
find $file_locations -maxdepth 1 -not -name '.*' | find $FILE_LOCATIONS -maxdepth 1 -not -name '.*' |
sed "s@$HOME@\~@" | sed "s@$HOME@\~@" |
sed 's/^/fil /' sed 's/^/fil /'
} }
@ -55,17 +64,19 @@ paste_emoji() {
nohup xclip -selection clipboard <(echo -n $emoji) &> /dev/null & nohup xclip -selection clipboard <(echo -n $emoji) &> /dev/null &
} }
# cat \ if [[ "$1" == "--print-only" ]]; then
# <(windows) \ cat \
# <($HOME/.rofi-list-git-repos.py --no-icon) \ <(windows) \
# <(read_apps) \ <($HOME/.rofi-list-git-repos.py --no-icon) \
# <(list_files) \ <(read_apps) \
# $HOME/.emojis <(list_files) \
# exit 1 $HOME/.emojis
exit 1
fi
choice="$(cat \ choice="$(cat \
<(windows) \ <(windows) \
<("$HOME/.rofi-list-git-repos.py" --no-icon) \ <("$HOME/.rofi-list-git-repos.py") \
<(read_apps) \ <(read_apps) \
<(list_files) \ <(list_files) \
"$HOME/.emojis" \ "$HOME/.emojis" \
@ -73,7 +84,7 @@ choice="$(cat \
case $choice in case $choice in
git*) git*)
nohup "$HOME/.rofi-list-git-repos.py" "$choice" &> /dev/null & setsid "$HOME/.rofi-list-git-repos.py" "$choice" &> /dev/null &
;; ;;
win*) win*)
wmctrl -i -R "$(xwininfo -root -tree | wmctrl -i -R "$(xwininfo -root -tree |
@ -88,7 +99,7 @@ case $choice in
paste_emoji "$choice" paste_emoji "$choice"
;; ;;
fil*) fil*)
nohup xdg-open "$(echo $choice | cut -c 5- | sed "s@~@$HOME@")" &> /dev/null & setsid xdg-open "$(echo $choice | cut -c 5- | sed "s@~@$HOME@")" &> /dev/null &
;; ;;
esac esac
sleep 0.1 sleep 0.1