-
Notifications
You must be signed in to change notification settings - Fork 15
/
dmenufm-open
executable file
·58 lines (54 loc) · 1.39 KB
/
dmenufm-open
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/sh
# See README.md for more detail
Extract () { # Usage: Extract [CMD] [FILE]
BaseName=${2##*/}
DirName=${BaseName%%.*}
CheckDeps "${1%% *}" || exit 1
[ ! -d "DirName" ] && mkdir -p "$DirName"
cd "$DirName" || return
$1 "$2" &&
NotiPrompt "$CHOICE extracted to $DirName" ||
{
cd .. && rm -rf $DirName
NotiPrompt "Extraction fail"
}
}
FileOpen () { # Usage: FileOpen [File/Dir]
mimetype=$(file --mime-type -b "$1" 2>/dev/null)
case "$1" in
*.tar.bz2|*.tar.xz|*.tbz2) Extract "tar xvjf" "$1" ;;
*.tar.gz|*.tgz) Extract "tar xvzf" "$1" ;;
*.lzma) Extract "unlzma" "$1" ;;
*.bz2) Extract "bunzip2" "$1" ;;
*.rar) Extract "unrar x -ad" "$1" ;;
*.gz) Extract "gunzip" "$1" ;;
*.tar) Extract "tar xvf" "$1" ;;
*.zip) Extract "unzip" "$1" ;;
*.Z) Extract "uncompress" "$1" ;;
*.7z) Extract "7z x" "$1" ;;
*.xz) Extract "unxz" "$1" ;;
*.cab) Extract "cabextract" "$1" ;;
*)
printf '%s' "$PWD" > "$FM_LASTPATH"
case "$mimetype" in
# Stolen from fff.
text/*|*x-empty*|*json*)
case "$TERMINAL" in
"") "${FM_OPENER:-${opener:-xdg-open}}" "$1" ;;
*)
[ -t 0 ] &&
"${EDITOR:-vi}" "$1" ||
$TERMINAL -e "${EDITOR:-vi}" "$1"
;;
esac
;;
inode/symlink)
path=$(readlink -f "$1")
FileOpen "$path"
;;
*)
${FM_OPENER:-${opener:-xdg-open}} "$1"
;;
esac
esac
}