Skip to content

Instantly share code, notes, and snippets.

@sampersand
Last active January 27, 2025 19:37
Show Gist options
  • Save sampersand/f6764cc0174cc5771d6fed0986be5d37 to your computer and use it in GitHub Desktop.
Save sampersand/f6764cc0174cc5771d6fed0986be5d37 to your computer and use it in GitHub Desktop.
################################################################################
# Option 1: Just repeat the defaults
################################################################################
alias ls="ls -ACFPq"
## ... other config ...
# macOS config
if [ "$(uname)" = Darwin ]; then
alias ls="ls -ACFPqGhbx"
# ...
fi
################################################################################
# Option 2: Use a function, and an alias
################################################################################
unalias ls >/dev/null 2>&1 # in case it was aliased already
ls () { command ls -ACFPq "$@" }
## ... other config ...
# macOS config
if [ "$(uname)" = Darwin ]; then
alias ls='ls -Ghbx'
# ...
fi
################################################################################
# Option 3: Use `eval`
################################################################################
alias ls='ls -ACFPq'
## ... other config ...
# macOS config
if [ "$(uname)" = Darwin ]; then
POSIXLY_CORRECT=1 # For Bash
alias "$(alias ls)Ghbx"
unset -v POSIXLY_CORRECT
# ...
fi
################################################################################
# Option 4: Use a variable and unset it
################################################################################
__scratch=
[ "$(uname)" = Darwin ] && __scratch=Ghbx
alias ls="ls -ACFPq$__scratch"
unset -v __scratch
# (Not a huge fan of this one, as it breaks apart my "macos-specific" config.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment