Skip to content

Instantly share code, notes, and snippets.

@mamemomonga
Created October 2, 2023 08:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mamemomonga/52d1544f9f51035925b3266c7feea651 to your computer and use it in GitHub Desktop.
Save mamemomonga/52d1544f9f51035925b3266c7feea651 to your computer and use it in GitHub Desktop.
長いパスのショートカットを作る
#!/bin/bash
# https://stackoverflow.com/questions/2683279/how-to-detect-if-a-script-is-being-sourced
is_sourced() {
if [ -n "$ZSH_VERSION" ]; then
case $ZSH_EVAL_CONTEXT in *:file:*) return 0;; esac
else # Add additional POSIX-compatible shell names here, if needed.
case ${0##*/} in dash|-dash|bash|-bash|ksh|-ksh|sh|-sh) return 0;; esac
fi
return 1 # NOT sourced.
}
if is_sourced; then
cd /path/to/super/long/long/long/long
else
echo "以下のように実行して下さい"
echo " . ./cd-longlonglong.sh"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment