cd on exit, subshell stuff

This commit is contained in:
Dylan Araps 2020-08-06 13:28:39 +03:00
parent 73075390e7
commit e2f2aa9caf
No known key found for this signature in database
GPG Key ID: 46D62DD9F1DE636E
2 changed files with 32 additions and 6 deletions

25
README
View File

@ -15,6 +15,8 @@ ________________________________________________________________________________
* no compilation needed
* correctly handles files with funky names (newlines, etc)
* works with very small terminal sizes.
* cd on exit
* works when run in subshell $(shfm)
*** see portability notes towards bottom of README.
@ -50,6 +52,29 @@ ________________________________________________________________________________
- [x] look into whether tput is feasible.
cd on exit
________________________________________________________________________________
On exit, the utility will print the path to working directory to <stdout>. To
disable this behavior, run with 'shfm >/dev/null'. Usage of this output is
rather flexible.
# cd to directory on exit
cd "$(shfm)"
# store pwd in var on exit
var=$(shfm)
# store pwd in a file one exit
shfm > file
For ease of use, a wrapper function can be added to your .shellrc (.bashrc, etc).
shfm() {
cd "$(command shfm)"
}
opener
________________________________________________________________________________

13
shfm
View File

@ -32,10 +32,13 @@ term_setup() {
term_reset() {
esc DECAWM h
esc DECTCEM h
esc ED2
esc DECTCEM h >&2
esc ED2 >&2
esc DECSTBM
stty "$stty"
# needed for cd-on-exit
printf '%s\n' "$PWD" >&1
}
term_resize() {
@ -173,15 +176,13 @@ status_line() {
*) esc SGR 34 7 ;;
esac
printf '%s ' "($y/$1)"
printf '%*s\r%s ' "$COLUMNS" "" "($y/$1)"
case $ltype in
'') printf %s "$PWD" ;;
*) printf %s "$ltype"
esac
printf '%*s' "$COLUMNS" ""
esc SGR
esc DECRC
}
@ -401,4 +402,4 @@ main() {
done
}
main "$@"
main "$@" >/dev/tty