about summary refs log tree commit diff
path: root/.config/zsh/utils.zsh
diff options
context:
space:
mode:
Diffstat (limited to '.config/zsh/utils.zsh')
-rw-r--r--.config/zsh/utils.zsh50
1 files changed, 50 insertions, 0 deletions
diff --git a/.config/zsh/utils.zsh b/.config/zsh/utils.zsh
new file mode 100644
index 0000000..e368ea0
--- /dev/null
+++ b/.config/zsh/utils.zsh
@@ -0,0 +1,50 @@
+# utils.zsh
+# Replacements for coreutils, color and reasonable defaults for common tools, etc.
+
+function has () {
+	command -v "$@" &> /dev/null
+}
+
+# cat
+if has bat; then
+	alias cat='bat --plain --paging=never'
+fi
+# should consider another alias for --show-all (and --number on base cat) but it's not a good default
+
+# diff
+alias diff='diff --color'
+
+# grep
+grep_opts="--color=auto --exclude-dir=.git"
+alias grep="grep $grep_opts"
+alias egrep="egrep $grep_opts"
+alias fgrep="fgrep $grep_opts"
+unset grep_opts
+
+# ls
+if has exa; then
+	alias ls='exa'
+	alias ll='exa --long --header --all'
+elif ls --color &> /dev/null; then
+	alias ls='ls --color=auto'
+	alias ll='ls -l --almost-all --no-group --human-readable'
+else
+	# bsd/mac ls
+	export CLICOLOR='1'
+	alias ll='ls -hoA'
+fi
+
+# mkdir
+alias mkdir='mkdir -p'
+
+# gpg
+if has gpg2; then
+	alias gpg='gpg2'
+fi
+
+# cygwin-specific
+if [[ "$OSTYPE" == 'cygwin' ]]; then
+	alias sudo='cygstart --action=runas'
+fi
+
+unfunction has