Skip to content

Instantly share code, notes, and snippets.

@thugcee
Forked from eugene-eeo/st-launch.sh
Last active February 15, 2020 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thugcee/4323337f6548fa57477755f5839b7bc9 to your computer and use it in GitHub Desktop.
Save thugcee/4323337f6548fa57477755f5839b7bc9 to your computer and use it in GitHub Desktop.
lightweight rofi alternative
#!/bin/bash
GEOMETRY="80x20+570+300"
FONT="RobotoMono Nerd Font:size=12"
CLASS="stLaunch"
_st_fzf() {
fzf +m --tiebreak=length,end --layout=reverse --color=prompt:7,pointer:7,spinner:2,info:8,hl:2,hl+:2,marker:0 --margin=1,2 --prompt='' $@
}
_st_run() {
st -f "$FONT" -c "$CLASS" -t 'st-launch' -a -g $GEOMETRY -e "$0" "$1" &
}
case "$1" in
# for some weird reason we need to sleep when we run pdetach
# to prevent it from exiting prematurely
_run)
f=$(compgen -c | sort | grep -v '[:!.{}]\|\[\[\|]]\|\[' | _st_fzf)
if [ $? = 0 ]; then
pdetach "$f"
sleep 0.25
fi
;;
_filter)
f=$(fd -d 3 . ~ | _st_fzf)
if [ $? = 0 ]; then
echo "$f" | xclip -i -selection clipboard
sleep 0.25
fi
;;
_window)
window_ids=$(xprop -root | grep '^_NET_CLIENT_LIST(WINDOW)' | cut -d ' ' -f5-)
IFS=', ' read -ra IDS <<< "$window_ids"
choice=$(
for wid in "${IDS[@]}"; do
name=$(xwininfo -id "$wid" -wm | grep '^xwininfo:' | cut -d ' ' -f 5-)
name="${name:1:-1}"
[[ $name != 'st-launch' ]] && echo "$wid $name"
done | _st_fzf --with-nth 2..
)
if [ $? = 0 ]; then
xdotool windowactivate $(echo "$choice" | cut -d ' ' -f1)
fi
;;
run) _st_run _run ;;
filter) _st_run _filter ;;
window) _st_run _window ;;
*) echo 'usage: st-launch run'
echo ' st-launch filter'
echo ' st-launch window'
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment