-
Notifications
You must be signed in to change notification settings - Fork 0
/
lfbundle.zshrc
34 lines (27 loc) · 888 Bytes
/
lfbundle.zshrc
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
# This file shall be sourced by zsh and provides the enviroment and setup
# required to extend lf's functionality.
lfbundle() {
# Initialize tempdir.
local basedir="$XDG_RUNTIME_DIR/lfbundle"
mkdir -p "$basedir"
LFBUNDLE_TEMPDIR="$(mktemp -d -p "$basedir" lfbundle-XXXXXX)"
# Arm cleanup trap.
lfbundle_cleanup() {
rm -rf "$LFBUNDLE_TEMPDIR"
unset LFBUNDLE_TEMPDIR
unfunction lfbundle_cleanup
}
setopt localoptions
setopt localtraps
# FIXME: Trap doesn't trigger if terminal is killed
trap 'lfbundle_cleanup' INT QUIT HUP
# Run lf.
LFBUNDLE_TEMPDIR="$LFBUNDLE_TEMPDIR" \lf \
-last-dir-path "$LFBUNDLE_TEMPDIR/lastdir" \
-config "$XDG_CONFIG_HOME/lfbundle/lfbundle.lfrc" \
"$@"
# Change working directory after closing lf.
[[ -f "$LFBUNDLE_TEMPDIR/changecwd" ]] && cd "$(cat "$LFBUNDLE_TEMPDIR/lastdir")" 2>/dev/null
lfbundle_cleanup
}
alias lf=lfbundle