From bb983ccbca3d119bedbc27f2db3bffe58d52dc24 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Wed, 16 Nov 2016 15:08:36 +0100 Subject: [PATCH] zsh: reorganize aliases + compdef's; remove compinit (zgen does this) --- shell/aliases.sh | 33 ++++++++++++++++++++++++++++-- shell/zsh/aliases.zsh | 43 +++------------------------------------- shell/zsh/completion.zsh | 9 --------- 3 files changed, 34 insertions(+), 51 deletions(-) diff --git a/shell/aliases.sh b/shell/aliases.sh index d62b2362..b1a2a3a8 100644 --- a/shell/aliases.sh +++ b/shell/aliases.sh @@ -12,15 +12,44 @@ alias ....='cd ../../..' alias -- -='cd -' alias ln="${aliases[ln]:-ln} -v" # verbose ln -alias ls="${aliases[ls]:-ls} --group-directories-first" alias l='ls -l' alias ll='ls -la' -alias pubkey='cat ~/.ssh/id_rsa.pub | y | echo "Public key copied to pasteboard."' +# notify me before clobbering files +alias rm='rm -i' +alias cp='cp -i' +alias mv='mv -i' + +alias gurl='curl --compressed' +alias mkdir='mkdir -p' +alias rsyncd='rsync -va --delete' # Hard sync two directories +alias wget='wget -c' # Resume dl if possible + +alias pubkey='cat ~/.ssh/id_rsa.pub' + +alias yd='youtube-dl' +alias ydm='youtube-dl --extract-audio --audio-format aac' + +# Always enable colored `grep` output +# Note: `GREP_OPTIONS="--color=auto"` is deprecated, hence the alias usage. +alias grep='grep --color=auto' +alias fgrep='fgrep --color=auto' +alias egrep='egrep --color=auto' + +alias mk='make' +alias exe='exercism' # For example, to list all directories that contain a certain file: find . -name # .gitattributes | map dirname alias map="xargs -n1" +o() { open "${1:-.}" } +c() { cd "$1" && ls -l; } take() { mkdir "$1" && cd "$1"; } hex() { echo -n $@ | xxd -psdu; } + +if command -v compdef >/dev/null; then + compdef o=open + compdef c=cd + compdef take=mkdir +fi diff --git a/shell/zsh/aliases.zsh b/shell/zsh/aliases.zsh index e18143cb..764778e7 100644 --- a/shell/zsh/aliases.zsh +++ b/shell/zsh/aliases.zsh @@ -1,49 +1,12 @@ -#!/usr/bin/env zsh - load shell/aliases.sh +loadall shell/zsh aliases.zsh +# +autoload -U zmv zman() { PAGER="less -g -s '+/^ "$1"'" man zshall; } -alias \?='since @$last' - -## Compilers, interpretors 'n builders ####################################### -alias mk='make' -alias exe='exercism' - -## Redefined tools ########################################################### -# Always enable colored `grep` output -# Note: `GREP_OPTIONS="--color=auto"` is deprecated, hence the alias usage. -alias grep='grep --color=auto' -alias fgrep='fgrep --color=auto' -alias egrep='egrep --color=auto' - alias ag='noglob ag' -alias gurl='curl --compressed' -alias mkdir='mkdir -p' -alias rsyncd='rsync -va --delete' # Hard sync two directories -alias ssh='ssh -C' # Compression for all ssh connections -alias wget='wget -c' # Resume dl if possible -alias ydl='youtube-dl' - -## New tools ################################################################# # Canonical hex dump; some systems have this symlinked is-callable hd || alias hd="hexdump -C" -## Remote resources ########################################################## -# URL-encode strings -alias urlencode='python -c "import sys, urllib as ul; print ul.quote_plus(sys.argv[1]);"' -# find conflicted dropbox files -alias findc="find . -iname '*conflicted*' -type f -exec echo '\"{}\" ' \;" -# Send to sprunge.us -alias bin="curl -s -F 'sprunge=<-' http://sprunge.us | head -n 1 | tr -d '\r\n ' | y" -# IP addresses -alias publicip="dig +short myip.opendns.com @resolver1.opendns.com" -alias ips="ifconfig -a | grep -o 'inet6\? \(addr:\)\?\s\?\(\(\([0-9]\+\.\)\{3\}[0-9]\+\)\|[a-fA-F0-9:]\+\)' | awk '{ sub(/inet6? (addr:)? ?/, \"\"); print }'" -# View HTTP traffic -alias sniff="sudo ngrep -d 'en0' -t '^(GET|POST) ' 'tcp and port 80'" -alias httpdump="sudo tcpdump -i en0 -n -s 0 -w - | grep -a -o -E \"Host\: .*|GET \/.*\"" -# Make URL REQUEST shortcuts -for method in GET HEAD POST PUT DELETE TRACE OPTIONS; do - alias "$method"="lwp-request -m '$method'" -done diff --git a/shell/zsh/completion.zsh b/shell/zsh/completion.zsh index bf2b4fef..d798474c 100644 --- a/shell/zsh/completion.zsh +++ b/shell/zsh/completion.zsh @@ -116,12 +116,3 @@ zstyle ':completion:*:(ssh|scp|rsync):*:hosts-host' ignored-patterns '*(.|:)*' l zstyle ':completion:*:(ssh|scp|rsync):*:hosts-domain' ignored-patterns '<->.<->.<->.<->' '^[-[:alnum:]]##(.[-[:alnum:]]##)##' '*@*' zstyle ':completion:*:(ssh|scp|rsync):*:hosts-ipaddr' ignored-patterns '^(<->.<->.<->.<->|(|::)([[:xdigit:].]##:(#c,2))##(|%*))' '127.0.0.<->' '255.255.255.255' '::1' 'fe80::*' - -## Custom compdefs ####################### - -compdef g=hub -compdef o=open -compdef take=mkdir -compdef t=tmux - -autoload -U compinit && compinit