dotfiles/.local/bin/tools/de

46 lines
1.7 KiB
Plaintext
Raw Normal View History

2021-05-06 17:21:41 +02:00
#!/bin/bash
2020-12-24 14:21:41 +01:00
#A script that launches documents in their respective viewers
#either via dmenu or fzf depending on the context
2021-06-19 14:41:32 +02:00
ppid () { ps -p $$ -o ppid=; }
2020-12-24 14:21:41 +01:00
shell="$(ps aux | grep $( ppid ) | head -n1 | awk '{print $11}' )"
document_dirs="$HOME/bks/* $HOME/eth/* $HOME/dox/* $HOME/dls/*"
2021-05-06 17:21:41 +02:00
#personally I don't want any files tagged with 'w' in ranger listed. (Watched videos)
tagged_file="${XDG_DATA_HOME:-$HOME/.local/share}/ranger/tagged"
filterfile="/tmp/tagged_filter"
grep -E '^w\:' "$tagged_file" | sed -E 's/^w\://' > "$filterfile"
2020-12-31 14:58:11 +01:00
#force launch dmenu via cmd
if [ "$1" = "launchdmenu" ]; then
2021-06-19 14:41:32 +02:00
#shellcheck disable=SC2086
2021-05-06 17:21:41 +02:00
file="$( find $document_dirs -type f | grep -vf "$filterfile" | sed "s|$HOME|~|"| dmenu -i -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)"
2021-06-19 14:41:32 +02:00
#shellcheck disable=SC2086
2021-05-06 17:21:41 +02:00
file="$( find $document_dirs -type f | grep -vf "$filterfile" | sed "s|$HOME|~|" | fzf -e --query="$*")"
2021-01-02 10:54:22 +01:00
path="$(printf '%s%s' "$HOME" "${file//\~/}")"
2020-12-24 14:21:41 +01:00
[ -z "$file" ] && exit
2021-01-02 10:54:22 +01:00
cd "$( dirname "$path" )" || exit
if rifle -l "$path" | head -n1 | grep -q 'EDITOR';then
rifle "$path"
2020-12-24 14:21:41 +01:00
else
rifle "$path" &
2020-12-24 14:21:41 +01:00
fi
cd "$currentdir" || exit
2020-12-31 14:58:11 +01:00
exit
#launch dmenu as it's probably in dmenu_run
else
2021-06-19 14:41:32 +02:00
#shellcheck disable=SC2086
2021-05-06 17:21:41 +02:00
file="$( find $document_dirs -type f | grep -vf "$filterfile" | sed "s|$HOME|~|" | dmenu -i -l 10 -p 'open what file?' -it "$*" )"
2020-12-31 14:58:11 +01:00
fi
#process selection if it's from dmenu
[ -z "$file" ] && exit
echo "$file" | sed "s|\~|$HOME|" |
2021-01-02 17:16:52 +01:00
while read -r pathfile; do
if rifle -l "$pathfile" | head -n1 | grep -q 'EDITOR';then
st rifle "$pathfile" &
2021-01-02 17:16:52 +01:00
else
rifle "$pathfile" &
2021-01-02 17:16:52 +01:00
fi
done
2021-05-06 17:21:41 +02:00
rm "$filterfile"