Skip to content

Instantly share code, notes, and snippets.

@dnnsmnstrr
Last active September 28, 2020 06:07
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 dnnsmnstrr/194d6db85ee7ce3f4b4a56b65767decc to your computer and use it in GitHub Desktop.
Save dnnsmnstrr/194d6db85ee7ce3f4b4a56b65767decc to your computer and use it in GitHub Desktop.
Shell Snippets

Shell Snippets

Most of these should work in bash and/or zsh

macOS

Get network location

CURRENT_LOCATION=$(scselect | tail -n +2 | egrep '^\ +\*' | cut -d \( -f 2- | sed 's/)$//')

Conditionals

case $CURRENT_LOCATION in
  'Home' )
    echo 'At home'
    ;;
  *)
    echo "Current network location: $CURRENT_LOCATION"
    ;;
esac

Files

echo $(basename "${filepath%.*}") # get filename from path

Date/Time

Get date in ISO8601 format

echo $(date '+%Y-%m-%d')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment