Skip to content

Instantly share code, notes, and snippets.

@nathanph
Created February 4, 2022 20:39
Show Gist options
  • Save nathanph/4008806e6f2a07280d2b7148e685e842 to your computer and use it in GitHub Desktop.
Save nathanph/4008806e6f2a07280d2b7148e685e842 to your computer and use it in GitHub Desktop.
exa wrapper which applies my preferred defaults and fixes some occassional errors
##
# exa CLI Configuration
##
if type "exa" > /dev/null; then
##
# Takes an exa command and returns the command with a fallback command
# appended in case of failures. The fallback command will be the original
# command except with the `--git` option removed.
##
function exa () {
local options="${@}"
local exa_options=( "${options}" )
local exa_options_without_git=()
# Create fallback options by removing all instances of `--git `.
local search='--git '
local replace=''
options_without_git="${options//"${search}"/"${replace}"}"
exa_options_without_git+=( "${options_without_git}" )
command exa ${=exa_options} 2> /dev/null \
|| command exa ${=exa_options_without_git}
}
# Options
default_options=(
'--group-directories-first'
'--icons'
'--classify'
# '--grid'
)
long_options=(
'--long'
'--header'
'--group'
'--accessed'
'--modified'
'--created'
# '--extended'
'--git'
)
tree_options=(
'--tree'
'--level 2'
)
# Default Command
exa_command="exa ${default_options}"
# List
alias ls="${exa_command} --grid"
alias la="${exa_command} --grid --all"
alias lsa='la'
# List Long
alias ll="${exa_command} ${long_options}"
alias lla="${exa_command} ${long_options} --grid --all"
# List Tree
alias lt="${exa_command} ${long_options} ${tree_options}"
alias lta="${exa_command} ${long_options} ${tree_options} --all"
alias tree='lt'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment