50 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
#!/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[-2]}/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" ;;
 | 
						|
        *)      prg="xdg-open" ;;
 | 
						|
esac
 | 
						|
 | 
						|
if [[ "$1" == '-S' && "$prg" =~ [feh|zathura] ]] ; then
 | 
						|
    swallow $prg "$selection"
 | 
						|
else
 | 
						|
    $prg "$selection"
 | 
						|
fi
 |