Skip to content

Instantly share code, notes, and snippets.

@IceCodeNew
Forked from k4yt3x/zshrc
Created June 16, 2020 04:54
Show Gist options
  • Save IceCodeNew/7ba4b1f60ef3bf576703df796835bde9 to your computer and use it in GitHub Desktop.
Save IceCodeNew/7ba4b1f60ef3bf576703df796835bde9 to your computer and use it in GitHub Desktop.

Revisions

  1. @k4yt3x k4yt3x revised this gist Jun 15, 2020. 1 changed file with 95 additions and 41 deletions.
    136 changes: 95 additions & 41 deletions zshrc
    Original file line number Diff line number Diff line change
    @@ -1,26 +1,31 @@
    # K4YT3X Public Server zshrc
    # Version 2020.06.12
    # K4YT3X Server/Community zshrc
    # Version 2020.06.15
    #
    # Licensed under the GNU General Public License Version 3 (GNU GPL v3),
    # available at: https://www.gnu.org/licenses/gpl-3.0.txt
    # (C) 2018-2020 K4YT3X
    #
    # Gist Page: https://gist.github.com/k4yt3x/3b41a1a65f5d3087133e449793eb8858
    # Short URL: akas.io/z
    # Quick Install: curl -LsSf akas.io/z -o ~/.zshrc

    # =========================== Global Variables
    # Add path for user with sudo
    export PATH=$PATH:/sbin

    # =========================== Aliases
    # Enhanced built-in commands
    alias a2='aria2c -x10'
    # enhanced built-in commands
    alias 7ze='7z a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on' # maximum compression ratio
    alias abs='realpath -e'
    alias c='clear'
    alias cl='cd && clear'
    alias clean='cat /dev/null > ~/.zsh_history'
    alias diffwatch='watch -n0 -d'
    alias get='wget --continue --tries=1 --connect-timeout=60 --read-timeout=300 --directory-prefix . --no-directories --no-background --progress=dot:default'
    alias get='aria2c -x10'
    alias ip6='ip -6'
    alias ipa='ip a | egrep --color=never -o "^[0-9]+: ([a-z0-9])+[0-9]*|.*link/(ether|loopback) ([a-zA-Z0-9]{2}:){5}[a-zA-Z0-9]{2}|.*inet ([0-9]{1,3}.){3}([0-9]{1,3}/[0-9]{1,2})|.*inet6 (([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/[0-9]{1,3}" | sed "s/link\/ether/Ethernet:/g" | sed "s/inet6/IPv6:/g" | sed "s/inet/IPv4:/g"'
    alias reload='exec "$SHELL"'
    alias sizes='du -sh * | sort -h'
    alias wgetx='wget --continue --tries=1 --connect-timeout=60 --read-timeout=300 --directory-prefix . --no-directories --no-background --progress=dot:default'

    # systemctl shortcuts
    alias start='sudo systemctl start'
    @@ -30,63 +35,99 @@ alias status='systemctl status'
    alias enable='sudo systemctl enable'
    alias disable='sudo systemctl disable'

    # Misc
    # APT shortcuts
    alias acs='apt-cache search'
    alias addkey='sudo apt-key adv --keyserver=hkp://keys.gnupg.net --recv'
    alias delkey='sudo apt-key del'
    alias listkeys='apt-key list'
    #alias apt='apt-fast'

    # misc
    alias ccat='pygmentize -g'
    alias egrep='egrep --color'
    alias grep='egrep --color'
    alias ll='ls -l'
    alias py='python3 -q'
    alias py2='python2 -q'
    alias py3='python3 -q'
    alias sudo='sudo ' # preserve aliases when using sudo

    # Verbose output
    alias rm='rm -v'
    alias mv='mv -v'
    # colored output
    alias dir='dir --color=auto'
    alias egrep='egrep --color'
    alias egrep='egrep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias grep='egrep --color'
    alias grep='grep --color=auto'
    alias ls='ls --color=auto'
    alias vdir='vdir --color=auto'

    # verbose output
    alias chgrp='chgrp -v'
    alias chmod='chmod -v'
    alias chown='chown -v'
    alias cp='cp -v'
    alias dhclient='dhclient -v'
    alias ln='ln -v'
    alias ssh='ssh -v'
    alias sftp='sftp -v'
    alias scp='scp -v'
    alias ping='ping -O'
    alias mkdir='mkdir -v'
    alias mtr4='mtr -4'
    alias mtr6='mtr -6'
    alias mv='mv -v'
    alias ping4='ping4 -O'
    alias ping6='ping6 -O'
    alias ping='ping -O'
    alias rm='rm -v'
    alias scp='scp -v'
    alias sftp='sftp -v'
    alias ssh='ssh -v'

    # Express edit
    # express edit
    alias vi3='vim ~/.config/i3/config'
    alias via='sudo vim /etc/apt/sources.list'
    alias vih='vim ~/.zsh_history'
    alias viz='vim ~/.zshrc'
    alias viv='vim ~/.vimrc'
    alias vir='sudo vim /etc/resolv.conf'
    alias viv='vim ~/.vimrc'
    alias viz='vim ~/.zshrc'

    # delete logs
    alias purge-histories='rm ~/.msf4/history ~/.cache/radare2/history ~/.bash_history ~/.python_history'
    alias purge-histories='rm ~/.msf4/history ~/.cache/radare2/history ~/.bash_history ~/.python_history ~/.wget-hsts ~/.node_repl_history'
    alias purge-x='rm ~/.xfce4-session.verbose-log ~/.xfce4-session.verbose-log.last ~/.xsession-errors ~/.xsession-errors.old'

    # Pip update all
    alias pip2-update="python -m pip install -U pip && python -m pip list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 sudo python -m pip install -U"
    # python modules

    # prettyjson formats stdin JSON string, e.g., curl example.com | prettyjson
    alias prettyjson="python3 -m json.tool"

    # httpserver starts a HTTP server under the local directory and listens on 0.0.0.0:8000
    alias httpserver="python3 -m http.server"

    # pip update all
    alias pip2-update="python2 -m pip install -U pip && python2 -m pip list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 sudo python2 -m pip install -U"
    alias pip3-update="python3 -m pip install -U pip && python3 -m pip list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 sudo python3 -m pip install -U"
    # alias pip2-update="pip list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 sudo pip install -U"
    # alias pip2-update="pip2 list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 sudo pip2 install -U"
    # alias pip3-update="pip3 list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 sudo pip3 install -U"

    # update sources.list
    alias update-sources='sudo mv /etc/apt/sources.list /etc/apt/sources.list.backup && sudo curl https://files.flexio.org/.tools/sources.list -o /etc/apt/sources.list'
    # update sources.list for Debian servers
    alias update-sources='sudo mv /etc/apt/sources.list /etc/apt/sources.list.backup && sudo curl https://files.k4yt3x.com/.tools/sources.list -o /etc/apt/sources.list'

    # Services shortcut
    # services shortcut
    alias start-tftpd="sudo atftpd --daemon --no-fork --port 69 --retry-timeout 5 --mcast-port 1758 --mcast-addr 239.239.239.0-255 --mcast-ttl 1 --maxthread 100 --verbose=5 /srv/tftp"

    # =========================== Custom Functions

    # ipinfo fetches and parses current or specified IP address information from ipinfo.io
    function ipinfo() {
    # If -s argument given await for stream input
    # if -s argument given await for stream input
    # otherwise query the first argument
    # If $1 is empty query current IP address
    if [[ $1 = "-s" ]] ; then
    /usr/bin/env python3 -c "import json,requests;print('\n'.join(['{0:15}{1}'.format(k.upper(), v) for k,v in json.loads(requests.get('https://ipinfo.io/$(cat /dev/stdin)').content).items()]))"
    /usr/bin/env python3 -c "import json,requests;print('\n'.join(['{0:15}{1}'.format(k.upper(), v) for k,v in json.loads(requests.get('https://ipinfo.io/\$(cat /dev/stdin)').content).items()]))"
    else
    /usr/bin/env python3 -c "import json,requests;print('\n'.join(['{0:15}{1}'.format(k.upper(), v) for k,v in json.loads(requests.get('https://ipinfo.io/$1').content).items()]))"
    fi
    }

    # Update zshrc from server
    # update zshrc from server
    function update-zshrc() {
    curl -L https://gist.github.com/k4yt3x/3b41a1a65f5d3087133e449793eb8858/raw -o ~/.zshrc
    curl -LsSf https://gist.github.com/k4yt3x/3b41a1a65f5d3087133e449793eb8858/raw -o ~/.zshrc

    # If current shell is zsh, restart shell
    if [ '/usr/bin/zsh' = "$SHELL" ] || [ '/bin/zsh' = "$SHELL" ] ; then
    @@ -117,26 +158,33 @@ EOF
    }


    # partially modified from Skywind3000's zshrc
    # original code: https://github.com/skywind3000/vim/blob/master/etc/zshrc.zsh

    # =========================== Check Requirements
    # Antigen: https://github.com/zsh-users/antigen
    # antigen: https://github.com/zsh-users/antigen
    ANTIGEN="$HOME/.local/bin/antigen.zsh"

    # Install antigen.zsh if not exist
    # install antigen.zsh if not exist
    if [ ! -f "$ANTIGEN" ]; then
    echo "Installing antigen ..."
    [ ! -d "$HOME/.local" ] && mkdir -p "$HOME/.local" 2> /dev/null
    [ ! -d "$HOME/.local/bin" ] && mkdir -p "$HOME/.local/bin" 2> /dev/null
    [ ! -f "$HOME/.z" ] && touch "$HOME/.z"
    URL="http://git.io/antigen"
    TMPFILE="/tmp/antigen.zsh"

    # Check http downloader
    if [ -x "$(which curl)" ]; then
    curl -L "$URL" -o "$TMPFILE"
    elif [ -x "$(which wget)" ]; then
    wget "$URL" -O "$TMPFILE"
    else
    echo "ERROR: please install curl or wget before installation !!"
    echo "ERROR: Please install curl or wget"
    exit
    fi

    # If return code not 0
    if [ ! $? -eq 0 ]; then
    echo "\nERROR: downloading antigen.zsh ($URL) failed !!"
    exit
    @@ -145,14 +193,17 @@ if [ ! -f "$ANTIGEN" ]; then
    mv "$TMPFILE" "$ANTIGEN"
    fi

    # Check git
    # check git
    if ! [ -x "$(which git)" ]; then
    echo "ERROR: Please install git"
    exit
    fi


    # =========================== Initialize Antigen and Plugins
    # initialize fail-over command prompt
    # export PS1="%n@%m:%~%# "

    # command prompt
    # blue prompt for root
    a=$(id|awk -F\( '{print $1}')
    @@ -167,10 +218,10 @@ else
    export PS1='%F{240}[%*] %F{11}%n%F{white}%#%B%m%b%F{yellow}[%~]%F{white}> '
    fi

    # Enable 256 color to make auto-suggestions look nice
    # enable 256 color to make auto-suggestions look nice
    export TERM="xterm-256color"

    # Load local bash/zsh compatible settings
    # load local bash/zsh compatible settings
    _INIT_SH_NOFUN=1
    [ -f "$HOME/.local/etc/init.sh" ] && source "$HOME/.local/etc/init.sh"

    @@ -180,11 +231,12 @@ _INIT_SH_NOFUN=1
    # WSL (aka Bash for Windows) doesn't work well with BG_NICE
    [ -d "/mnt/c" ] && [[ "$(uname -a)" == *Microsoft* ]] && unsetopt BG_NICE

    # Initialize antigen
    # initialize antigen
    source "$ANTIGEN"

    # Initialize oh-my-zsh
    # initialize oh-my-zsh
    antigen use oh-my-zsh
    # antigen bundle vi-mode

    # default bundles
    # visit https://github.com/unixorn/awesome-zsh-plugins
    @@ -292,14 +344,16 @@ setopt HIST_FIND_NO_DUPS # Do not display a line previously found.
    setopt HIST_IGNORE_SPACE # Don't record an entry starting with a space.
    setopt HIST_SAVE_NO_DUPS # Don't write duplicate entries in the history file.
    setopt HIST_REDUCE_BLANKS # Remove superfluous blanks before recording entry.
    setopt HIST_VERIFY # Don't execute immediately upon history expansion.
    setopt HIST_VERIFY # Don't execute immediately upon history expansion.


    # =========================== File and Configuration Sourcing
    # activate torch if exists
    [ -f "$HOME/torch/install/bin/torch-activate" ] && . "$HOME/torch/install/bin/torch-activate"

    # source function.sh if it exists
    [ -f "$HOME/.local/etc/function.sh" ] && . "$HOME/.local/etc/function.sh"

    # ignore complition
    # ignore completion
    zstyle ':completion:*:complete:-command-:*:*' ignored-patterns '*.pdf|*.exe|*.dll'
    zstyle ':completion:*:*sh:*:' tag-order files
  2. @k4yt3x k4yt3x revised this gist Jun 12, 2020. 1 changed file with 23 additions and 1 deletion.
    24 changes: 23 additions & 1 deletion zshrc
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    # K4YT3X Public Server zshrc
    # Version 2020.01.13
    # Version 2020.06.12
    # Licensed under the GNU General Public License Version 3 (GNU GPL v3),
    # available at: https://www.gnu.org/licenses/gpl-3.0.txt
    # (C) 2018-2020 K4YT3X
    @@ -94,6 +94,28 @@ function update-zshrc() {
    fi
    }
    # ipa prints distilled output of the "ip a" command
    # version 1.1.0
    function ipa() {
    python3 - $@ << EOF
    import contextlib, json, subprocess, sys
    e = ['ip', '-j', 'a']
    e.extend(['s', sys.argv[1]]) if len(sys.argv) >= 2 else None
    s = subprocess.Popen(e, stdout=subprocess.PIPE)
    j = s.communicate()[0]
    sys.exit(s.returncode) if s.returncode != 0 else None
    for i in json.loads(j):
    with contextlib.suppress(Exception):
    print('{}: {}'.format(i['ifindex'], i['ifname']))
    print(' MAC: {}'.format(i['address'])) if i.get('address') else None
    print(' MAC (Permanent): {}'.format(i['permaddr'])) if i.get('permaddr') else None
    for a in i['addr_info']:
    family = 'IPv4' if a['family'] == 'inet' else a['family']
    family = 'IPv6' if a['family'] == 'inet6' else family
    print(' {}: {}/{}'.format(family, a['local'], a['prefixlen']))
    EOF
    }
    # =========================== Check Requirements
    # Antigen: https://github.com/zsh-users/antigen
  3. @k4yt3x k4yt3x revised this gist Jan 14, 2020. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions zshrc
    Original file line number Diff line number Diff line change
    @@ -137,10 +137,12 @@ a=$(id|awk -F\( '{print $1}')
    if [ "$a" = "uid=0" ]
    then
    # for root
    export PS1='%F{240}[%*] %F{33}%n%F{white}%#%F{240}%m%F{blue}[%~]%F{white}> '
    #export PS1='%F{240}[%*] %F{33}%n%F{white}%#%F{240}%m%F{blue}[%~]%F{white}> '
    export PS1='%F{240}[%*] %F{33}%n%F{white}%#%B%m%b%F{blue}[%~]%F{white}> '
    else
    # for other users
    export PS1='%F{240}[%*] %F{11}%n%F{white}%#%F{240}%m%F{yellow}[%~]%F{white}> '
    #export PS1='%F{240}[%*] %F{11}%n%F{white}%#%F{240}%m%F{yellow}[%~]%F{white}> '
    export PS1='%F{240}[%*] %F{11}%n%F{white}%#%B%m%b%F{yellow}[%~]%F{white}> '
    fi
    # Enable 256 color to make auto-suggestions look nice
  4. @k4yt3x k4yt3x revised this gist Jan 14, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion zshrc
    Original file line number Diff line number Diff line change
    @@ -86,7 +86,7 @@ function ipinfo() {
    # Update zshrc from server
    function update-zshrc() {
    curl https://gist.github.com/k4yt3x/3b41a1a65f5d3087133e449793eb8858/raw -o ~/.zshrc
    curl -L https://gist.github.com/k4yt3x/3b41a1a65f5d3087133e449793eb8858/raw -o ~/.zshrc
    # If current shell is zsh, restart shell
    if [ '/usr/bin/zsh' = "$SHELL" ] || [ '/bin/zsh' = "$SHELL" ] ; then
  5. @k4yt3x k4yt3x revised this gist Jan 14, 2020. 1 changed file with 3 additions and 4 deletions.
    7 changes: 3 additions & 4 deletions zshrc
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,8 @@
    # K4YT3X Public Server zshrc
    # Version 2019.12.16
    # (C) K4YT3X 2018-2019
    # Version 2020.01.13
    # Licensed under the GNU General Public License Version 3 (GNU GPL v3),
    # available at: https://www.gnu.org/licenses/gpl-3.0.txt
    # (C) 2019 K4YT3X
    # (C) 2018-2020 K4YT3X
    # Gist Page: https://gist.github.com/k4yt3x/3b41a1a65f5d3087133e449793eb8858

    # =========================== Global Variables
    @@ -87,7 +86,7 @@ function ipinfo() {
    # Update zshrc from server
    function update-zshrc() {
    curl https://gist.github.com/k4yt3x/3b41a1a65f5d3087133e449793eb8858/raw/4ee9173d923983cd3c45dbc7b27ad44306bff820/zshrc -o ~/.zshrc
    curl https://gist.github.com/k4yt3x/3b41a1a65f5d3087133e449793eb8858/raw -o ~/.zshrc
    # If current shell is zsh, restart shell
    if [ '/usr/bin/zsh' = "$SHELL" ] || [ '/bin/zsh' = "$SHELL" ] ; then
  6. @k4yt3x k4yt3x revised this gist Dec 17, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion zshrc
    Original file line number Diff line number Diff line change
    @@ -87,7 +87,7 @@ function ipinfo() {
    # Update zshrc from server
    function update-zshrc() {
    curl https://files.flexio.org/.tools/zshrc -o ~/.zshrc
    curl https://gist.github.com/k4yt3x/3b41a1a65f5d3087133e449793eb8858/raw/4ee9173d923983cd3c45dbc7b27ad44306bff820/zshrc -o ~/.zshrc
    # If current shell is zsh, restart shell
    if [ '/usr/bin/zsh' = "$SHELL" ] || [ '/bin/zsh' = "$SHELL" ] ; then
  7. @k4yt3x k4yt3x revised this gist Dec 16, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion zshrc
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    # Licensed under the GNU General Public License Version 3 (GNU GPL v3),
    # available at: https://www.gnu.org/licenses/gpl-3.0.txt
    # (C) 2019 K4YT3X
    # Gist Page: https://gist.github.com/k4yt3x/ecd7597ad0eff23c21f34b32cce6922d
    # Gist Page: https://gist.github.com/k4yt3x/3b41a1a65f5d3087133e449793eb8858

    # =========================== Global Variables
    # Add path for user with sudo
  8. @k4yt3x k4yt3x revised this gist Dec 16, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion zshrc
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # K4YT3X Server zshrc
    # K4YT3X Public Server zshrc
    # Version 2019.12.16
    # (C) K4YT3X 2018-2019
    # Licensed under the GNU General Public License Version 3 (GNU GPL v3),
  9. @k4yt3x k4yt3x created this gist Dec 16, 2019.
    282 changes: 282 additions & 0 deletions zshrc
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,282 @@
    # K4YT3X Server zshrc
    # Version 2019.12.16
    # (C) K4YT3X 2018-2019
    # Licensed under the GNU General Public License Version 3 (GNU GPL v3),
    # available at: https://www.gnu.org/licenses/gpl-3.0.txt
    # (C) 2019 K4YT3X
    # Gist Page: https://gist.github.com/k4yt3x/ecd7597ad0eff23c21f34b32cce6922d

    # =========================== Global Variables
    # Add path for user with sudo
    export PATH=$PATH:/sbin

    # =========================== Aliases
    # Enhanced built-in commands
    alias a2='aria2c -x10'
    alias abs='realpath -e'
    alias c='clear'
    alias cl='cd && clear'
    alias clean='cat /dev/null > ~/.zsh_history'
    alias diffwatch='watch -n0 -d'
    alias get='wget --continue --tries=1 --connect-timeout=60 --read-timeout=300 --directory-prefix . --no-directories --no-background --progress=dot:default'
    alias ip6='ip -6'
    alias ipa='ip a | egrep --color=never -o "^[0-9]+: ([a-z0-9])+[0-9]*|.*link/(ether|loopback) ([a-zA-Z0-9]{2}:){5}[a-zA-Z0-9]{2}|.*inet ([0-9]{1,3}.){3}([0-9]{1,3}/[0-9]{1,2})|.*inet6 (([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/[0-9]{1,3}" | sed "s/link\/ether/Ethernet:/g" | sed "s/inet6/IPv6:/g" | sed "s/inet/IPv4:/g"'
    alias reload='exec "$SHELL"'

    # systemctl shortcuts
    alias start='sudo systemctl start'
    alias stop='sudo systemctl stop'
    alias restart='sudo systemctl restart'
    alias status='systemctl status'
    alias enable='sudo systemctl enable'
    alias disable='sudo systemctl disable'

    # Misc
    alias addkey='sudo apt-key adv --keyserver=hkp://keys.gnupg.net --recv'
    alias ccat='pygmentize -g'
    alias egrep='egrep --color'
    alias grep='egrep --color'
    alias ll='ls -l'
    alias sudo='sudo ' # preserve aliases when using sudo

    # Verbose output
    alias rm='rm -v'
    alias mv='mv -v'
    alias cp='cp -v'
    alias ln='ln -v'
    alias ssh='ssh -v'
    alias sftp='sftp -v'
    alias scp='scp -v'
    alias ping='ping -O'
    alias ping4='ping4 -O'
    alias ping6='ping6 -O'

    # Express edit
    alias vih='vim ~/.zsh_history'
    alias viz='vim ~/.zshrc'
    alias viv='vim ~/.vimrc'
    alias vir='sudo vim /etc/resolv.conf'

    # delete logs
    alias purge-histories='rm ~/.msf4/history ~/.cache/radare2/history ~/.bash_history ~/.python_history'
    alias purge-x='rm ~/.xfce4-session.verbose-log ~/.xfce4-session.verbose-log.last ~/.xsession-errors ~/.xsession-errors.old'

    # Pip update all
    alias pip2-update="python -m pip install -U pip && python -m pip list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 sudo python -m pip install -U"
    alias pip3-update="python3 -m pip install -U pip && python3 -m pip list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 sudo python3 -m pip install -U"
    # alias pip2-update="pip list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 sudo pip install -U"
    # alias pip3-update="pip3 list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 sudo pip3 install -U"

    # update sources.list
    alias update-sources='sudo mv /etc/apt/sources.list /etc/apt/sources.list.backup && sudo curl https://files.flexio.org/.tools/sources.list -o /etc/apt/sources.list'

    # Services shortcut
    alias start-tftpd="sudo atftpd --daemon --no-fork --port 69 --retry-timeout 5 --mcast-port 1758 --mcast-addr 239.239.239.0-255 --mcast-ttl 1 --maxthread 100 --verbose=5 /srv/tftp"

    # =========================== Custom Functions
    function ipinfo() {
    # If -s argument given await for stream input
    # otherwise query the first argument
    # If $1 is empty query current IP address
    if [[ $1 = "-s" ]] ; then
    /usr/bin/env python3 -c "import json,requests;print('\n'.join(['{0:15}{1}'.format(k.upper(), v) for k,v in json.loads(requests.get('https://ipinfo.io/$(cat /dev/stdin)').content).items()]))"
    else
    /usr/bin/env python3 -c "import json,requests;print('\n'.join(['{0:15}{1}'.format(k.upper(), v) for k,v in json.loads(requests.get('https://ipinfo.io/$1').content).items()]))"
    fi
    }
    # Update zshrc from server
    function update-zshrc() {
    curl https://files.flexio.org/.tools/zshrc -o ~/.zshrc
    # If current shell is zsh, restart shell
    if [ '/usr/bin/zsh' = "$SHELL" ] || [ '/bin/zsh' = "$SHELL" ] ; then
    exec "$SHELL"
    fi
    }
    # =========================== Check Requirements
    # Antigen: https://github.com/zsh-users/antigen
    ANTIGEN="$HOME/.local/bin/antigen.zsh"
    # Install antigen.zsh if not exist
    if [ ! -f "$ANTIGEN" ]; then
    echo "Installing antigen ..."
    [ ! -d "$HOME/.local" ] && mkdir -p "$HOME/.local" 2> /dev/null
    [ ! -d "$HOME/.local/bin" ] && mkdir -p "$HOME/.local/bin" 2> /dev/null
    [ ! -f "$HOME/.z" ] && touch "$HOME/.z"
    URL="http://git.io/antigen"
    TMPFILE="/tmp/antigen.zsh"
    if [ -x "$(which curl)" ]; then
    curl -L "$URL" -o "$TMPFILE"
    elif [ -x "$(which wget)" ]; then
    wget "$URL" -O "$TMPFILE"
    else
    echo "ERROR: please install curl or wget before installation !!"
    exit
    fi
    if [ ! $? -eq 0 ]; then
    echo "\nERROR: downloading antigen.zsh ($URL) failed !!"
    exit
    fi;
    echo "move $TMPFILE to $ANTIGEN"
    mv "$TMPFILE" "$ANTIGEN"
    fi
    # Check git
    if ! [ -x "$(which git)" ]; then
    echo "ERROR: Please install git"
    exit
    fi
    # =========================== Initialize Antigen and Plugins
    # command prompt
    # blue prompt for root
    a=$(id|awk -F\( '{print $1}')
    if [ "$a" = "uid=0" ]
    then
    # for root
    export PS1='%F{240}[%*] %F{33}%n%F{white}%#%F{240}%m%F{blue}[%~]%F{white}> '
    else
    # for other users
    export PS1='%F{240}[%*] %F{11}%n%F{white}%#%F{240}%m%F{yellow}[%~]%F{white}> '
    fi
    # Enable 256 color to make auto-suggestions look nice
    export TERM="xterm-256color"
    # Load local bash/zsh compatible settings
    _INIT_SH_NOFUN=1
    [ -f "$HOME/.local/etc/init.sh" ] && source "$HOME/.local/etc/init.sh"
    # exit for non-interactive shell
    [[ $- != *i* ]] && return
    # WSL (aka Bash for Windows) doesn't work well with BG_NICE
    [ -d "/mnt/c" ] && [[ "$(uname -a)" == *Microsoft* ]] && unsetopt BG_NICE
    # Initialize antigen
    source "$ANTIGEN"
    # Initialize oh-my-zsh
    antigen use oh-my-zsh
    # default bundles
    # visit https://github.com/unixorn/awesome-zsh-plugins
    antigen bundle git
    # antigen bundle heroku
    antigen bundle pip
    antigen bundle svn-fast-info
    # antigen bundle command-not-find
    antigen bundle colorize
    antigen bundle github
    antigen bundle python
    antigen bundle rupa/z z.sh
    # antigen bundle z
    antigen bundle zsh-users/zsh-autosuggestions
    antigen bundle zsh-users/zsh-completions
    # antigen bundle supercrabtree/k
    antigen bundle Vifon/deer
    # uncomment the line below to enable theme
    #antigen theme bureau
    # check login shell
    if [[ -o login ]]; then
    [ -f "$HOME/.local/etc/login.sh" ] && source "$HOME/.local/etc/login.sh"
    [ -f "$HOME/.local/etc/login.zsh" ] && source "$HOME/.local/etc/login.zsh"
    fi
    # syntax color definition
    ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern)
    typeset -A ZSH_HIGHLIGHT_STYLES
    # ZSH_HIGHLIGHT_STYLES[command]=fg=white,bold
    # ZSH_HIGHLIGHT_STYLES[alias]='fg=magenta,bold'
    ZSH_HIGHLIGHT_STYLES[default]=none
    ZSH_HIGHLIGHT_STYLES[unknown-token]=fg=009
    ZSH_HIGHLIGHT_STYLES[reserved-word]=fg=009,standout
    ZSH_HIGHLIGHT_STYLES[alias]=fg=cyan,bold
    ZSH_HIGHLIGHT_STYLES[builtin]=fg=cyan,bold
    ZSH_HIGHLIGHT_STYLES[function]=fg=cyan,bold
    ZSH_HIGHLIGHT_STYLES[command]=fg=white,bold
    ZSH_HIGHLIGHT_STYLES[precommand]=fg=white,underline
    ZSH_HIGHLIGHT_STYLES[commandseparator]=none
    ZSH_HIGHLIGHT_STYLES[hashed-command]=fg=009
    ZSH_HIGHLIGHT_STYLES[path]=fg=214,underline
    ZSH_HIGHLIGHT_STYLES[globbing]=fg=063
    ZSH_HIGHLIGHT_STYLES[history-expansion]=fg=white,underline
    ZSH_HIGHLIGHT_STYLES[single-hyphen-option]=none
    ZSH_HIGHLIGHT_STYLES[double-hyphen-option]=none
    ZSH_HIGHLIGHT_STYLES[back-quoted-argument]=none
    ZSH_HIGHLIGHT_STYLES[single-quoted-argument]=fg=063
    ZSH_HIGHLIGHT_STYLES[double-quoted-argument]=fg=063
    ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]=fg=009
    ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]=fg=009
    ZSH_HIGHLIGHT_STYLES[assign]=none
    # load local config
    [ -f "$HOME/.local/etc/config.zsh" ] && source "$HOME/.local/etc/config.zsh"
    [ -f "$HOME/.local/etc/local.zsh" ] && source "$HOME/.local/etc/local.zsh"
    # enable syntax highlighting
    antigen bundle zsh-users/zsh-syntax-highlighting
    antigen apply
    # setup for deer
    autoload -U deer
    zle -N deer
    # default keymap
    bindkey -s '\ee' 'vim\n'
    bindkey '\eh' backward-char
    bindkey '\el' forward-char
    bindkey '\ej' down-line-or-history
    bindkey '\ek' up-line-or-history
    # bindkey '\eu' undo
    bindkey '\eH' backward-word
    bindkey '\eL' forward-word
    bindkey '\eJ' beginning-of-line
    bindkey '\eK' end-of-line
    bindkey -s '\eo' 'cd ..\n'
    bindkey -s '\e;' 'll\n'
    bindkey '\e[1;3D' backward-word
    bindkey '\e[1;3C' forward-word
    bindkey '\e[1;3A' beginning-of-line
    bindkey '\e[1;3B' end-of-line
    bindkey '\ev' deer
    # options
    unsetopt correct_all
    setopt BANG_HIST # Treat the '!' character specially during expansion.
    setopt INC_APPEND_HISTORY # Write to the history file immediately, not when the shell exits.
    setopt SHARE_HISTORY # Share history between all sessions.
    setopt HIST_EXPIRE_DUPS_FIRST # Expire duplicate entries first when trimming history.
    setopt HIST_IGNORE_DUPS # Don't record an entry that was just recorded again.
    setopt HIST_IGNORE_ALL_DUPS # Delete old recorded entry if new entry is a duplicate.
    setopt HIST_FIND_NO_DUPS # Do not display a line previously found.
    setopt HIST_IGNORE_SPACE # Don't record an entry starting with a space.
    setopt HIST_SAVE_NO_DUPS # Don't write duplicate entries in the history file.
    setopt HIST_REDUCE_BLANKS # Remove superfluous blanks before recording entry.
    setopt HIST_VERIFY # Don't execute immediately upon history expansion.
    # =========================== File and Configuration Sourcing
    # source function.sh if it exists
    [ -f "$HOME/.local/etc/function.sh" ] && . "$HOME/.local/etc/function.sh"
    # ignore complition
    zstyle ':completion:*:complete:-command-:*:*' ignored-patterns '*.pdf|*.exe|*.dll'
    zstyle ':completion:*:*sh:*:' tag-order files