proper files loc
This commit is contained in:
		
							parent
							
								
									dbf546e61c
								
							
						
					
					
						commit
						7dd2a2e4a6
					
				
							
								
								
									
										51
									
								
								scripts/files/rofi-files
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										51
									
								
								scripts/files/rofi-files
									
									
									
									
									
										Executable file
									
								
							@ -0,0 +1,51 @@
 | 
			
		||||
#!/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
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user