cd on exit, subshell stuff

This commit is contained in:
Dylan Araps committed 2020-08-06 13:28:39 +03:00
1 parent 73075390e7
commit e2f2aa9caf
2 files changed
+32 -6

No files matched your search

+25
View File
@@ -15,6 +15,8 @@ ________________________________________________________________________________
* no compilation needed * no compilation needed
* correctly handles files with funky names (newlines, etc) * correctly handles files with funky names (newlines, etc)
* works with very small terminal sizes. * works with very small terminal sizes.
* cd on exit
* works when run in subshell $(shfm)
*** see portability notes towards bottom of README. *** see portability notes towards bottom of README.
@@ -50,6 +52,29 @@ ________________________________________________________________________________
- [x] look into whether tput is feasible. - [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 opener
________________________________________________________________________________ ________________________________________________________________________________
+7 -6
View File
@@ -32,10 +32,13 @@ term_setup() {
term_reset() { term_reset() {
esc DECAWM h esc DECAWM h
esc DECTCEM h esc DECTCEM h >&2
esc ED2 esc ED2 >&2
esc DECSTBM esc DECSTBM
stty "$stty" stty "$stty"
# needed for cd-on-exit
printf '%s\n' "$PWD" >&1
} }
term_resize() { term_resize() {
@@ -173,15 +176,13 @@ status_line() {
*) esc SGR 34 7 ;; *) esc SGR 34 7 ;;
esac esac
printf '%s ' "($y/$1)" printf '%*s\r%s ' "$COLUMNS" "" "($y/$1)"
case $ltype in case $ltype in
'') printf %s "$PWD" ;; '') printf %s "$PWD" ;;
*) printf %s "$ltype" *) printf %s "$ltype"
esac esac
printf '%*s' "$COLUMNS" ""
esc SGR esc SGR
esc DECRC esc DECRC
} }
@@ -401,4 +402,4 @@ main() {
done done
} }
main "$@" main "$@" >/dev/tty