You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.1 KiB
Plaintext
52 lines
1.1 KiB
Plaintext
2 years ago
|
#!/bin/bash
|
||
|
|
||
|
# getting focused pwd
|
||
|
PID=$(xdotool getwindowfocus getwindowpid)
|
||
|
child=$PID
|
||
|
children=()
|
||
|
while [ -n "$child" ] ; do
|
||
|
children+=($child)
|
||
|
child=$(pgrep -P $child)
|
||
|
done
|
||
|
|
||
|
last_ps=$(ps ${children[-1]} | grep -v PID | awk '{print $5}')
|
||
|
|
||
|
if [ "$last_ps" == "tmux" ] ; then
|
||
|
current_pane=$(tmux list-panes | grep '(active)' | grep -o '^[0-9]')
|
||
|
cwd=$(tmux display-message -p -t $current_pane -F '#{pane_current_path}')
|
||
|
else
|
||
|
cwd=$(readlink -e /proc/${children[-1]}/cwd)
|
||
|
fi
|
||
|
|
||
|
# change to the directory
|
||
|
cd $cwd
|
||
|
files=$(find * -type f)
|
||
|
|
||
|
selection=$(echo "$files" | rofi-dmenu)
|
||
|
|
||
|
# exit on quit
|
||
|
if [ -z "$selection" ] ; then
|
||
|
exit 0
|
||
|
fi
|
||
|
|
||
|
# grab extension
|
||
|
extension=$(echo "$selection" | grep -o '.\([a-zA-Z]\+\)$')
|
||
|
|
||
|
# get proper opener
|
||
|
case "$extension" in
|
||
|
'.pdf') prg="zathura" ;;
|
||
|
'.md') prg="vim" ;;
|
||
|
'.png') prg="feh" ;;
|
||
|
'.jpg') prg="feh" ;;
|
||
|
'.jpeg') prg="feh" ;;
|
||
|
'.odt') prg="libreoffice" ;;
|
||
|
'.ods') prg="libreoffice" ;;
|
||
|
*) prg="xdg-open" ;;
|
||
|
esac
|
||
|
|
||
|
if [[ "$1" == '-S' && "$prg" =~ [feh|zathura] ]] ; then
|
||
|
swallow $prg "$selection"
|
||
|
else
|
||
|
$prg "$selection"
|
||
|
fi
|