dotfiles/.local/bin/tools/de

35 lines
1.3 KiB
Plaintext
Raw Normal View History

2020-12-24 14:21:41 +01:00
#!/bin/bash
#A script that launches documents in their respective viewers
#either via dmenu or fzf depending on the context
ppid () { ps -p ${1:-$$} -o ppid=; }
shell="$(ps aux | grep $( ppid ) | head -n1 | awk '{print $11}' )"
document_dirs="$HOME/bks/* $HOME/eth/* $HOME/dox/*"
2020-12-31 14:58:11 +01:00
#force launch dmenu via cmd
if [ "$1" = "launchdmenu" ]; then
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?')"
2020-12-24 14:21:41 +01:00
#/bin/sh means it's probably from dmenu_run (it's ugly but works)
2020-12-31 14:58:11 +01:00
elif [ ! "$shell" = "/bin/sh" ]; then
2020-12-24 14:21:41 +01:00
currentdir="$(pwd)"
file="$( du -a $document_dirs | awk '{for(i=2; i<NF; i++){printf("%s ", $i)}printf("%s\n", $NF)}' | fzf -e --query="$*")"
[ -z "$file" ] && exit
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-12-31 14:58:11 +01:00
exit
#launch dmenu as it's probably in dmenu_run
else
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 "$*" )"
fi
#process selection if it's from dmenu
[ -z "$file" ] && exit
cd "$( dirname "$file" )" || exit
if rifle -l "$file" | head -n1 | grep -q 'EDITOR';then
st rifle "$file"
else
rifle "$file"
2020-12-24 14:21:41 +01:00
fi