-
Notifications
You must be signed in to change notification settings - Fork 8
/
09_file_managers.zsh
58 lines (50 loc) · 1.86 KB
/
09_file_managers.zsh
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
# Wrapper to set skin depending on terminal and effective permissions
if (( ${+commands[mc]} )); then
mc () {
if [[ -v MC_SID ]]; then
print "Midnight Commander is already running, press Ctrl+O to return to it"
return
fi
if [[ "${TERM}" = "linux" && "${EUID}" -ne 0 ]]; then
export MC_SKIN=modarcon16-defbg
elif [[ "${TERM}" = "linux" && "${EUID}" -eq 0 ]]; then
export MC_SKIN=modarcon16root-defbg
elif [[ "${TERM}" != "linux" && "${EUID}" -ne 0 ]]; then
export MC_SKIN=modarin256-defbg
elif [[ "${TERM}" != "linux" && "${EUID}" -eq 0 ]]; then
export MC_SKIN=modarin256root-defbg
fi
local mc_pwd_file="${XDG_RUNTIME_DIR}/mc.pwd.$$"
command mc -P "${mc_pwd_file}" "${@}"
if [[ -r ${mc_pwd_file} ]]; then
local mc_last_pwd=$(<"${mc_pwd_file}")
if [[ -d ${mc_last_pwd} ]] && [[ ${mc_last_file} != ${PWD} ]]; then
cd "${mc_last_pwd}"
fi
zf_rm -f "${mc_pwd_file}"
fi
}
fi
if (( ${+commands[ranger]} )); then
ranger () {
if [[ -v RANGER_LEVEL ]]; then
exit
fi
local ranger_pwd_file="$(mktemp -t ranger_pwd.XXXXXXXXXX)"
command ranger --choosedir="${ranger_pwd_file}" "${@}"
if [[ -r ${ranger_pwd_file} ]]; then
local ranger_last_pwd=$(<"${ranger_pwd_file}")
if [[ -d ${ranger_last_pwd} ]] && [[ ${ranger_last_pwd} != ${PWD} ]]; then
cd "${ranger_last_pwd}"
fi
zf_rm -f "${ranger_pwd_file}"
fi
}
# Change ranger CWD to PWD on subshell exit
if [[ -v RANGER_LEVEL ]]; then
_ranger_cd () {
print "cd ${PWD}" > "${XDG_RUNTIME_DIR}/ranger-ipc.${PPID}"
}
add-zsh-hook zshexit _ranger_cd
fi
fi