Skip to content

Commit

Permalink
ensure script can be sourced or copied and pasted (#32)
Browse files Browse the repository at this point in the history
- if sourced, the script will `exit`, instead of the old behavior, which generated a second login shell atop the first one
- if copied and pasted, the script will `return` without exiting and closing the current shell
- if not sourced, then `$0` is likely `-sh` or `sh` (or `-zsh` or `zsh`), which, without a leading login hyphen `-`, is a terminating substring of `${SHELL##*/}`; this heuristic will determine the appropriate behavior
- the script no longer calls `exec -l`, which, even obfuscated, is not defined by POSIX

Signed-off-by: Lucas Larson <[email protected]>
  • Loading branch information
LucasLarson authored Jul 21, 2023
1 parent df8d226 commit 195f7a8
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions update
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env sh
update='2023-07-15'
update='2023-07-16'
IFS="$(command printf -- ' \t\n|')" && IFS="${IFS%'|'}"
command printf -- '\n\n .___ __\n __ ________ __\174 _\057____ _\057 \174_ ____\n\174 \174 \134____ \134 \057 __ \174\134__ \134\134 __\134\057 __ \134\n\174 \174 \057 \174_\076 \076 \057_\057 \174 \057 __ \134\174 \174 \134 ___\057\n\174____\057\174 __\057\134____ \174\050____ \057__\174 \134___ \076\n \174__\174 \134\057 \134\057 \134\057\n a Lucas Larson production\n\n' >&2 && command sleep 1
command printf -- '\360\237\223\241 verifying network connectivity' >&2
Expand Down Expand Up @@ -130,4 +130,4 @@ if command -v -- rehash >/dev/null 2>&1; then rehash; fi
update=''
unset -v -- update 2>/dev/null
command printf -- '\n\342%s\234\205 update complete\n' "${update-}" >&2
"$(command -v -- exec)" -l -- "${SHELL##*/}"
case "${SHELL##*/}" in *"${0##*-}") return ;; *) exit ;; esac

0 comments on commit 195f7a8

Please sign in to comment.