# # Editor # export EDITOR="vim" # # Pager # if (( $+commands[vim] )) && [[ -f ~/.vim/bin/vimpager ]]; then export PAGER=~/.vim/bin/vimpager alias less="$PAGER" alias more="$PAGER" elif (( $+commands[less] )); then export PAGER=less alias more="$PAGER" elif (( $+commands[more] )); then export PAGER=more fi export GIT_PAGER="$PAGER" # # Common aliases / functions # export QUOTING_STYLE='literal' alias ls='ls --group-directories-first --color=auto' alias l='ls --group-directories-first -lsh --color=auto' alias rm='rm -i' alias mv='mv -i' alias cp='cp -i' alias vlock='clear;vlock' alias q='clear;exit' alias grep="grep --color=auto" alias egrep="egrep --color=auto" alias mgrep="grep -rnisH --color=auto" alias rsu="sudo -E zsh" alias reloadsh="exec zsh" alias tmux="tmux -2" alias md="mkdir -p" mcd() { mkdir -p "$@" && cd "$@" } ffi() { find -iname "$@" } # # Log viewers aliases # if (( $+commands[ccze] )); then alias alog="tail -n 300 -F /var/log/auth.log | ccze" alias mlog="tail -n 300 -F /var/log/mail.log | ccze" alias slog="tail -n 300 -F /var/log/syslog | ccze" alias xlog="tail -n 300 -F /var/log/Xorg.0.log | ccze" else alias alog="tail -n 300 -F /var/log/auth.log" alias mlog="tail -n 300 -F /var/log/mail.log" alias slog="tail -n 300 -F /var/log/syslog" alias xlog="tail -n 300 -F /var/log/Xorg.0.log" fi # using colortail if available (freebsd) if (( $+commands[colortail] )); then alias slog="colortail -n 60 -k /usr/local/share/examples/colortail/conf.messages -f /var/log/syslog" fi # # System tools aliases # alias df='df -h' if (( $+commands[pydf] )); then alias df="pydf -h" fi function mount() { if [ $# = 0 ]; then command mount -lv | column -t else command mount $@ fi } # # Sysadmin stuff # if (( $+commands[dig] )); then alias mx="dig +short MX" alias ns="dig +short NS" elif (( $+commands[host] )); then alias mx="host -t MX" alias ns="host -t NS" fi alias scp_nosec="scp -o 'StrictHostKeyChecking=no' -o 'UserKnownHostsFile=/dev/null'" alias ssh_nosec="ssh -o 'StrictHostKeyChecking=no' -o 'UserKnownHostsFile=/dev/null'" # Network port-status() { if [ $# != 2 ]; then print "Usage: $0 [IP|HOSTNAME] [PORT|SERVICE]" else local host="${1}" local service="${2}" if nc -w 5 -z "${host}" "${service}" ; then print "Port or sevice '${service}' is opened on '${host}'" else print "Port or sevice '${service}' is closed on '${host}'" fi fi } # OpenSSL for i in sha512 sha256 sha1 md5 ; do ssl-cert-$i() { openssl x509 -noout -fingerprint -$i -in $1 } done ssl-crt-fp() { for i in sha512 sha256 sha1 md5; do ssl-cert-$i $1 done } ssl-crt-info() { openssl x509 -noout -text -in $1 } ssl-crt-info() { openssl x509 -noout -text -in $1 } ssl-csr-info() { openssl req -noout -text -in $1 } ssl-csr-subject() { openssl req -noout -text -in $1 | \ sed -r -n 's/^\s+Subject: (.*)/\1/p' | \ sed -r 's#(^|, )#/#g' } ssl-csr-gen() { local domain="${1:-mydomain}" local keysize="${2:-4096}" local keytype="${3:-rsa}" local digest="${4:-sha256}" local subject="/C=FR/ST=IDF/L=Paris/O=${domain}/CN=${domain}/emailAddress=admin@${domain}" if [ -n "${CSR_SUBJECT}" ]; then subject="${CSR_SUBJECT}" fi printf "Generating csr/key for ${domain} with ${keytype}/${keysize} key and ${digest} digest...\n" openssl req \ -subj "${subject}" \ -nodes \ -${digest} \ -newkey ${keytype}:${keysize} \ -keyout ${domain}.key \ -out ${domain}.csr ssl-csr-info ${domain}.csr } ssl-csr-gen-from() { local oldcsr="${1}" local domain="${2}" local subject="$(ssl-csr-subject "${oldcsr}")" CSR_SUBJECT="$(ssl-csr-subject "${oldcsr}")" ssl-csr-gen "${domain}" } # # Devel tools aliases # if (( $+commands[colormake] )); then alias make="colormake" fi # # Git Flow stuff # git-flow-release() { local version_next="" if [[ "${1}" = "" ]]; then local version_current="$(git lasttag 2>/dev/null)" if [[ "${version_current}" != "" ]]; then local version_minor="${version_current##*.}" local version_major="${version_current%.*}" local version_next="${version_major}.$((version_minor+1))" fi else version_next="${1}" fi if [[ "${version_next}" != "" ]]; then export GIT_MERGE_AUTOEDIT=no git flow release start "${version_next}" && \ GIT_MERGE_AUTOEDIT=no git flow release finish -m "${version_next}" "${version_next}" else printf "%s: tag is missing\n" "${0}" >&2 fi } alias gfr="git-flow-release" # # Mssh stuff # if [ -f ~/.ssh/config ]; then hosts=($(grep '^Host [^*]' ~/.ssh/config | sed 's/Host //')) compctl -k hosts mssh fi # # Hosting stuff # http_auth_ssha() { read "username?username: " read "password?password: " salt="$(openssl rand -base64 3)" sha1="$(printf "%s%s" "${password}" "${salt}" | openssl dgst -binary -sha1 | sed 's#$#'"${salt}"'#' | base64)" printf "%s:{SSHA}%s\n" "${username}" "${sha1}" } # # DNS stuff # myip () { # Get public IP address from opendns ipv4= ipv6= ip4_resolver="resolver1.opendns.com" ip6_resolver="2620:0:ccc::2" if (( $+commands[dig] )); then ipv4=$(dig +short myip.opendns.com "@${ip4_resolver}") ipv6=$(dig AAAA +short myip.opendns.com "@${ip6_resolver}") elif (( $+commands[host] )); then ipv4=$(LANG=C host -t A myip.opendns.com "${ip4_resolver}" | sed -r -n 's/^.* has address (.*)$/\1/p') ipv6=$(LANG=C host -t AAAA myip.opendns.com "${ip6_resolver}" | sed -r -n 's/^.* has IPv6 address (.*)$/\1/p') fi if [[ -n "${ipv4}" ]]; then printf "IPv4 is %s\n" "${ipv4}" else printf "IPv4 not found\n" >&2 fi if [[ -n "${ipv6}" ]]; then printf "IPv6 is %s\n" "${ipv6}" else printf "IPv6 not found\n" >&2 fi }