updated stuff

This commit is contained in:
Nikolas Weger 2019-12-11 12:13:54 +01:00
parent c37679a883
commit c4ff5a9900
24 changed files with 138 additions and 30 deletions

87
zsh/plgs/aliases.zsh Normal file
View file

@ -0,0 +1,87 @@
# Advanced Aliases.
# Use with caution
#
# ls, the common ones I use a lot shortened for rapid fire usage
alias l='ls -lFh' #size,show type,human readable
alias la='ls -lAFh' #long list,show almost all,show type,human readable
alias lr='ls -tRFh' #sorted by date,recursive,show type,human readable
alias lt='ls -ltFh' #long list,sorted by date,show type,human readable
alias ll='ls -l' #long list
alias ldot='ls -ld .*'
alias lS='ls -1FSsh'
alias lart='ls -1Fcart'
alias lrt='ls -1Fcrt'
alias zshrc='${=EDITOR} ~/.zshrc' # Quick access to the ~/.zshrc file
alias grep='grep --color'
alias sgrep='grep -R -n -H -C 5 --exclude-dir={.git,.svn,CVS} '
alias t='tail -f'
# Command line head / tail shortcuts
alias -g H='| head'
alias -g T='| tail'
alias -g G='| grep'
alias -g L="| less"
alias -g M="| most"
alias -g LL="2>&1 | less"
alias -g CA="2>&1 | cat -A"
alias -g NE="2> /dev/null"
alias -g NUL="> /dev/null 2>&1"
alias -g P="2>&1| pygmentize -l pytb"
alias dud='du -d 1 -h'
alias duf='du -sh *'
alias fd='find . -type d -name'
alias ff='find . -type f -name'
alias h='history'
alias hgrep="fc -El 0 | grep"
alias help='man'
alias p='ps -f'
alias sortnr='sort -n -r'
alias unexport='unset'
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
# zsh is able to auto-do some kungfoo
# depends on the SUFFIX :)
if is-at-least 4.2.0; then
# open browser on urls
if [[ -n "$BROWSER" ]]; then
_browser_fts=(htm html de org net com at cx nl se dk)
for ft in $_browser_fts; do alias -s $ft=$BROWSER; done
fi
_editor_fts=(cpp cxx cc c hh h inl asc txt TXT tex)
for ft in $_editor_fts; do alias -s $ft=$EDITOR; done
if [[ -n "$XIVIEWER" ]]; then
_image_fts=(jpg jpeg png gif mng tiff tif xpm)
for ft in $_image_fts; do alias -s $ft=$XIVIEWER; done
fi
_media_fts=(ape avi flv m4a mkv mov mp3 mpeg mpg ogg ogm rm wav webm)
for ft in $_media_fts; do alias -s $ft=mplayer; done
#read documents
alias -s pdf=acroread
alias -s ps=gv
alias -s dvi=xdvi
alias -s chm=xchm
alias -s djvu=djview
#list whats inside packed file
alias -s zip="unzip -l"
alias -s rar="unrar l"
alias -s tar="tar tf"
alias -s tar.gz="echo "
alias -s ace="unace l"
fi
# Make zsh know about hosts already accessed by SSH
zstyle -e ':completion:*:(ssh|scp|sftp|rsh|rsync):hosts' hosts 'reply=(${=${${(f)"$(cat {/etc/ssh_,~/.ssh/known_}hosts(|2)(N) /dev/null)"}%%[# ]*}//,/ })'

117
zsh/plgs/appup.zsh Normal file
View file

@ -0,0 +1,117 @@
# Docker
_appup_docker () {
if hash docker-compose >/dev/null 2>&1; then
# Check if docker-machine has been started
if hash docker-machine >/dev/null 2>&1; then
if docker-machine status | grep -qi "Stopped"; then
read -q "REPLY?Docker Machine is not running, would you like to start it? [y/n] "
echo ""
if [[ "$REPLY" == "y" ]]; then
docker-machine start default && eval $(docker-machine env default)
echo ""
else
return
fi
fi
fi
# Check YAML extension
compose_file=''
compose_project_file=''
if [ -e "docker-compose.yml" ]; then
compose_file='docker-compose.yml'
elif [ -e "docker-compose.yaml" ]; then
compose_file='docker-compose.yaml'
fi
# <cmd> <project name> will look for docker-compose.<project name>.yml
if [ -n "$2" ]; then
if [ -e "docker-compose.$2.yml" ]; then
compose_project_file="docker-compose.$2.yml"
elif [ -e "docker-compose.$2.yaml" ]; then
compose_project_file="docker-compose.$2.yaml"
fi
if [ -n "$compose_project_file" ]; then
# Override project name from custom env
if [ -e ".env.$2" ]; then
project=$(source ".env.$2"; echo $COMPOSE_PROJECT_NAME)
if [ -n $project ]; then
docker-compose -p "${project}" -f "$compose_file" -f "$compose_project_file" $1 "${@:3}"
return
fi
fi
docker-compose -f "$compose_file" -f "$compose_project_file" $1 "${@:3}"
return
fi
fi
docker-compose $1 "${@:2}"
else
echo >&2 "Docker compose file found but docker-compose is not installed."
fi
}
# Vagrant
_appup_vagrant () {
if hash vagrant >/dev/null 2>&1; then
vagrant $1 "${@:2}"
else
echo >&2 "Vagrant file found but vagrant is not installed."
fi
}
up () {
if [ -e "docker-compose.yml" ] || [ -e "docker-compose.yaml" ]; then
_appup_docker up "$@"
elif [ -e "Vagrantfile" ]; then
_appup_vagrant up "$@"
elif hash up >/dev/null 2>&1; then
env up "$@"
fi
}
down () {
if [ -e "docker-compose.yml" ] || [ -e "docker-compose.yaml" ]; then
_appup_docker down "$@"
elif [ -e "Vagrantfile" ]; then
_appup_vagrant destroy "$@"
elif hash down >/dev/null 2>&1; then
env down "$@"
fi
}
start () {
if [ -e "docker-compose.yml" ] || [ -e "docker-compose.yaml" ]; then
_appup_docker start "$@"
elif [ -e "Vagrantfile" ]; then
_appup_vagrant up "$@"
elif hash start >/dev/null 2>&1; then
env start "$@"
fi
}
restart () {
if [ -e "docker-compose.yml" ] || [ -e "docker-compose.yaml" ]; then
_appup_docker restart "$@"
elif [ -e "Vagrantfile" ]; then
_appup_vagrant reload "$@"
elif hash start >/dev/null 2>&1; then
env start "$@"
fi
}
stop () {
if [ -e "docker-compose.yml" ] || [ -e "docker-compose.yaml" ]; then
_appup_docker stop "$@"
elif [ -e "Vagrantfile" ]; then
_appup_vagrant halt "$@"
elif hash stop >/dev/null 2>&1; then
env stop "$@"
fi
}

71
zsh/plgs/extract.zsh Normal file
View file

@ -0,0 +1,71 @@
alias x=extract
extract() {
local remove_archive
local success
local extract_dir
if (( $# == 0 )); then
cat <<-'EOF' >&2
Usage: extract [-option] [file ...]
Options:
-r, --remove Remove archive after unpacking.
EOF
fi
remove_archive=1
if [[ "$1" == "-r" ]] || [[ "$1" == "--remove" ]]; then
remove_archive=0
shift
fi
while (( $# > 0 )); do
if [[ ! -f "$1" ]]; then
echo "extract: '$1' is not a valid file" >&2
shift
continue
fi
success=0
extract_dir="${1:t:r}"
case "${1:l}" in
(*.tar.gz|*.tgz) (( $+commands[pigz] )) && { pigz -dc "$1" | tar xv } || tar zxvf "$1" ;;
(*.tar.bz2|*.tbz|*.tbz2) tar xvjf "$1" ;;
(*.tar.xz|*.txz)
tar --xz --help &> /dev/null \
&& tar --xz -xvf "$1" \
|| xzcat "$1" | tar xvf - ;;
(*.tar.zma|*.tlz)
tar --lzma --help &> /dev/null \
&& tar --lzma -xvf "$1" \
|| lzcat "$1" | tar xvf - ;;
(*.tar) tar xvf "$1" ;;
(*.gz) (( $+commands[pigz] )) && pigz -dk "$1" || gunzip -k "$1" ;;
(*.bz2) bunzip2 "$1" ;;
(*.xz) unxz "$1" ;;
(*.lzma) unlzma "$1" ;;
(*.z) uncompress "$1" ;;
(*.zip|*.war|*.jar|*.sublime-package|*.ipsw|*.xpi|*.apk|*.aar|*.whl) unzip "$1" -d $extract_dir ;;
(*.rar) unrar x -ad "$1" ;;
(*.7z) 7za x "$1" ;;
(*.deb)
mkdir -p "$extract_dir/control"
mkdir -p "$extract_dir/data"
cd "$extract_dir"; ar vx "../${1}" > /dev/null
cd control; tar xzvf ../control.tar.gz
cd ../data; extract ../data.tar.*
cd ..; rm *.tar.* debian-binary
cd ..
;;
(*)
echo "extract: '$1' cannot be extracted" >&2
success=1
;;
esac
(( success = $success > 0 ? $success : $? ))
(( $success == 0 )) && (( $remove_archive == 0 )) && rm "$1"
shift
done
}

12
zsh/plgs/gitignore.zsh Normal file
View file

@ -0,0 +1,12 @@
function gi() { curl -fL https://www.gitignore.io/api/${(j:,:)@} }
_gitignoreio_get_command_list() {
curl -sfL https://www.gitignore.io/api/list | tr "," "\n"
}
_gitignoreio () {
compset -P '*,'
compadd -S '' `_gitignoreio_get_command_list`
}
compdef _gitignoreio gi

8
zsh/plgs/systemctl.zsh Normal file
View file

@ -0,0 +1,8 @@
cmds=(status show start stop reload restart enable disable daemon-reload)
for cmd in $cmds; do
alias sc-$cmd="sudo systemctl $cmd"
done
alias sc-enablenow="sc-enable --now"
alias sc-disablenow="sc-disable --now"