-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlfcd_sh
More file actions
executable file
·24 lines (20 loc) · 762 Bytes
/
lfcd_sh
File metadata and controls
executable file
·24 lines (20 loc) · 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/sh
### Wrapper for [lf](https://github.com/gokcehan/lf) to **cd** to
### the last visited directory on exit. Usefull for keybinds. Slight adaptation
### from the suggestion given on [lf's](https://github.com/gokcehan/lf) wiki.
### Open lf on current directory and cd to the last shown dir on exit
# this was needed because of a race condition so keep it in mind for the future :/
#sleep 0.1
tmp="$(mktemp)"
lf -last-dir-path="$tmp" "$@"
# cleanup terminal window name changes (not standard)
printf "st" | chtermname
if [ -f "$tmp" ]; then
dir="$(cat "$tmp")"
rm -f "$tmp"
# we cd to the folder even if we're already there so we always exec bash on that folder
if [ -d "$dir" ]; then
cd "$dir" || cd "$HOME" || exit 1
exec "$SHELL"
fi
fi