2020-07-04 14:23:27 +02:00
|
|
|
#!/bin/bash
|
2020-12-31 12:18:33 +01:00
|
|
|
#A script that launches documents in their respective viewers
|
|
|
|
#either via dmenu or fzf depending on the context
|
2020-10-28 13:48:43 +01:00
|
|
|
ppid () { ps -p ${1:-$$} -o ppid=; }
|
|
|
|
shell="$(ps aux | grep $( ppid ) | head -n1 | awk '{print $11}' )"
|
2020-12-31 12:18:33 +01:00
|
|
|
document_dirs="$HOME/.config/* $HOME/.local/src/* $HOME/.local/bin/*"
|
|
|
|
#/bin/sh means it's probably from dmenu_run (it's ugly but works)
|
2020-10-28 13:48:43 +01:00
|
|
|
if [ "$shell" = "/bin/sh" ]; then
|
2020-12-31 12:18:33 +01:00
|
|
|
file="$( du -a $document_dirs | awk '{for(i=2; i<NF; i++){printf("%s ", $i)}printf("%s\n", $NF)}'| dmenu -l 10 -p 'open what file?' -it "$*" )"
|
2020-10-28 13:48:43 +01:00
|
|
|
[ -z "$file" ] && exit
|
2020-12-31 12:18:33 +01:00
|
|
|
cd "$( dirname "$file" )" || exit
|
|
|
|
if rifle -l "$file" | head -n1 | grep -q 'EDITOR';then
|
|
|
|
st rifle "$file"
|
|
|
|
else
|
|
|
|
rifle "$file"
|
|
|
|
fi
|
2020-10-28 13:48:43 +01:00
|
|
|
else
|
|
|
|
currentdir="$(pwd)"
|
2020-12-31 12:18:33 +01:00
|
|
|
file="$( du -a $document_dirs | awk '{for(i=2; i<NF; i++){printf("%s ", $i)}printf("%s\n", $NF)}' | fzf -e --query="$*")"
|
2020-10-28 13:48:43 +01:00
|
|
|
[ -z "$file" ] && exit
|
2020-12-31 12:18:33 +01:00
|
|
|
cd "$( dirname "$file" )" || exit
|
|
|
|
if rifle -l "$file" | head -n1 | grep -q 'EDITOR';then
|
|
|
|
rifle "$file"
|
|
|
|
else
|
|
|
|
rifle "$file" & disown
|
|
|
|
fi
|
|
|
|
cd "$currentdir" || exit
|
2020-10-28 13:48:43 +01:00
|
|
|
fi
|