2023-04-04 20:16:50 -04:00
|
|
|
#!/bin/bash
|
|
|
|
|
2023-04-28 11:23:13 -04:00
|
|
|
WINDOW_NAME="active-sofi-window"
|
2023-04-28 16:09:04 -04:00
|
|
|
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="$?"
|
2023-04-28 11:23:13 -04:00
|
|
|
|
2023-04-04 20:16:50 -04:00
|
|
|
# Open search window or raise existing one
|
|
|
|
if [[ "$1" == "--launch" ]]; then
|
2023-04-28 16:09:04 -04:00
|
|
|
if (($IS_X11)) && existing="$(xdotool search $WINDOW_NAME)"; then
|
2023-04-04 20:16:50 -04:00
|
|
|
xdotool windowraise "$existing"
|
|
|
|
else
|
2023-04-28 16:09:04 -04:00
|
|
|
# xfce4-terminal --role="$WINDOW_NAME" --title="$WINDOW_NAME" --startup-id="$WINDOW_NAME" -e "bash -c '$HOME/.sofi.sh'"
|
|
|
|
xterm -fa 'Monospaced' -fs 10 -e "bash -c '$HOME/.sofi.sh'"
|
|
|
|
# st -e bash -c '$HOME/.sofi.sh'"
|
2023-04-04 20:16:50 -04:00
|
|
|
fi
|
|
|
|
exit $?
|
|
|
|
fi
|
|
|
|
|
|
|
|
windows() {
|
2023-04-28 16:09:04 -04:00
|
|
|
if ! (($IS_X11)); then
|
|
|
|
return
|
|
|
|
fi
|
2023-04-04 20:16:50 -04:00
|
|
|
xprop -root _NET_CLIENT_LIST |
|
|
|
|
pcregrep -o1 '# (.*)' |
|
|
|
|
sed 's/, /\n/g' |
|
2023-04-28 16:09:04 -04:00
|
|
|
xargs -I {} -n1 xprop -id {} _NET_WM_NAME |
|
2023-04-04 20:16:50 -04:00
|
|
|
grep -v '"Desktop"\|"xfce4-panel"' |
|
|
|
|
sed 's/_NET_WM_NAME(UTF8_STRING) = "/win /' | sed 's/"$//'
|
|
|
|
}
|
|
|
|
|
|
|
|
read_apps() {
|
2023-04-28 16:09:04 -04:00
|
|
|
cat "$CACHE_FILE"
|
2023-04-04 20:16:50 -04:00
|
|
|
# shellcheck disable=SC2086
|
2023-04-28 16:09:04 -04:00
|
|
|
nohup find $APP_LOCATIONS -name '*.desktop' -exec grep '^Name=' {} \; |
|
|
|
|
egrep -iv "$IGNORED_APPS" |
|
|
|
|
sed 's/Name=/app /' > "$CACHE_FILE" &
|
2023-04-04 20:16:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
open_app() {
|
|
|
|
app="$(echo "$1" | cut -c 5-)"
|
|
|
|
# shellcheck disable=SC2086
|
2023-04-28 16:09:04 -04:00
|
|
|
find $APP_LOCATIONS -name '*.desktop' | while read -r f; do
|
2023-04-04 20:16:50 -04:00
|
|
|
if grep "Name=$app" "$f" &> /dev/null; then
|
2023-04-28 11:23:13 -04:00
|
|
|
setsid exo-open "$f" >/dev/null 2>&1 </dev/null &
|
2023-04-04 20:16:50 -04:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
list_files() {
|
2023-04-28 16:09:04 -04:00
|
|
|
find $FILE_LOCATIONS -maxdepth 1 -not -name '.*' |
|
2023-04-04 20:16:50 -04:00
|
|
|
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 &
|
|
|
|
}
|
|
|
|
|
2023-04-28 16:09:04 -04:00
|
|
|
if [[ "$1" == "--print-only" ]]; then
|
|
|
|
cat \
|
|
|
|
<(windows) \
|
|
|
|
<($HOME/.rofi-list-git-repos.py --no-icon) \
|
|
|
|
<(read_apps) \
|
|
|
|
<(list_files) \
|
|
|
|
$HOME/.emojis
|
|
|
|
exit 1
|
|
|
|
fi
|
2023-04-04 20:16:50 -04:00
|
|
|
|
|
|
|
choice="$(cat \
|
|
|
|
<(windows) \
|
2023-04-28 16:09:04 -04:00
|
|
|
<("$HOME/.rofi-list-git-repos.py") \
|
2023-04-04 20:16:50 -04:00
|
|
|
<(read_apps) \
|
|
|
|
<(list_files) \
|
|
|
|
"$HOME/.emojis" \
|
|
|
|
| fzf)"
|
|
|
|
|
|
|
|
case $choice in
|
|
|
|
git*)
|
2023-04-28 16:09:04 -04:00
|
|
|
setsid "$HOME/.rofi-list-git-repos.py" "$choice" &> /dev/null &
|
2023-04-04 20:16:50 -04:00
|
|
|
;;
|
|
|
|
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*)
|
2023-04-28 16:09:04 -04:00
|
|
|
setsid xdg-open "$(echo $choice | cut -c 5- | sed "s@~@$HOME@")" &> /dev/null &
|
2023-04-04 20:16:50 -04:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
sleep 0.1
|