66 lines
2.0 KiB
Bash
66 lines
2.0 KiB
Bash
# A collection of various shell utilities.
|
|
|
|
autoload colors && colors
|
|
|
|
# Detect the type and extract an archive file.
|
|
extract() {
|
|
if [ -f $1 ]; then
|
|
case $1 in
|
|
*.tar.bz2) tar xvjf $1 ;;
|
|
*.tar.gz) tar xvzf $1 ;;
|
|
*.tar.xz) gunzip $1 ;;
|
|
*.bz2) bunzip2 $1 ;;
|
|
*.rar) unrar x $1 ;;
|
|
*.gz) gunzip $1 ;;
|
|
*.tar) tar xvf $1 ;;
|
|
*.tbz2) tar xvjf $1 ;;
|
|
*.tgz) tar xvzf $1 ;;
|
|
*.zip) unzip $1 ;;
|
|
*.Z) uncompress $1 ;;
|
|
*.7z) 7zr x $1 ;;
|
|
*) echo "$fg[red]error:$reset_color unable to extract '$1'" ;;
|
|
esac
|
|
else
|
|
echo "$fg[red]error:$reset_color file not found '$1'"
|
|
fi
|
|
}
|
|
|
|
if which bat &> /dev/null; then
|
|
# Wrap bat to specify a theme, always enable color, pipe the output to less.
|
|
# Both --theme and --color can be specified multiple times and will override
|
|
# these defaults.
|
|
bat() {
|
|
command bat --theme='Solarized (dark)' --color always \
|
|
--paging always --pager 'less -R' "$@"
|
|
}
|
|
fi
|
|
|
|
if which docker-machine &> /dev/null; then
|
|
# Wrap the docker command to print a message if a docker-machine is not
|
|
# running, rather than just stating it can not find it's socket.
|
|
docker() {
|
|
command docker "$@"
|
|
if ! docker-machine active &> /dev/null; then
|
|
echo "$fg[red]error:$reset_color no active host found, run:" \
|
|
"docker-machine start <machine>"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# Wrap the docker-machine command to automatically update the environment.
|
|
# When a machine is started, set the environment variables provided by
|
|
# docker-machine env <machine>. When a machine is stopped, unset the same
|
|
# variables.
|
|
docker-machine() {
|
|
command docker-machine "$@"
|
|
if [ "start" = "$1" ]; then
|
|
eval `docker-machine env $2`
|
|
elif [ "stop" = "$1" ]; then
|
|
unset DOCKER_MACHINE_NAME
|
|
unset DOCKER_CERT_PATH
|
|
unset DOCKER_HOST
|
|
unset DOCKER_TLS_VERIFY
|
|
fi
|
|
}
|
|
fi
|