dotfiles/fake_home/.sofi.sh

106 lines
2.5 KiB
Bash
Executable File

#!/bin/bash
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
if [[ "$1" == "--launch" ]]; then
if (($IS_X11)) && existing="$(xdotool search $WINDOW_NAME)"; then
xdotool windowraise "$existing"
else
# 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'"
fi
exit $?
fi
windows() {
if ! (($IS_X11)); then
return
fi
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/"$//'
}
read_apps() {
cat "$CACHE_FILE"
# shellcheck disable=SC2086
nohup find $APP_LOCATIONS -name '*.desktop' -exec grep '^Name=' {} \; |
egrep -iv "$IGNORED_APPS" |
sed 's/Name=/app /' > "$CACHE_FILE" &
}
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
setsid exo-open "$f" >/dev/null 2>&1 </dev/null &
return
fi
done
}
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 &
}
if [[ "$1" == "--print-only" ]]; then
cat \
<(windows) \
<($HOME/.rofi-list-git-repos.py --no-icon) \
<(read_apps) \
<(list_files) \
$HOME/.emojis
exit 1
fi
choice="$(cat \
<(windows) \
<("$HOME/.rofi-list-git-repos.py") \
<(read_apps) \
<(list_files) \
"$HOME/.emojis" \
| fzf)"
case $choice in
git*)
setsid "$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*)
setsid xdg-open "$(echo $choice | cut -c 5- | sed "s@~@$HOME@")" &> /dev/null &
;;
esac
sleep 0.1