Skip to content

Instantly share code, notes, and snippets.

@InvisibleRasta
Last active April 12, 2020 04:00
Show Gist options
  • Save InvisibleRasta/44f87daf14fb282819e4910b120a6a51 to your computer and use it in GitHub Desktop.
Save InvisibleRasta/44f87daf14fb282819e4910b120a6a51 to your computer and use it in GitHub Desktop.
My .zshrc with .oh-my-zsh
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# shell-color-scripts from AUR
/opt/shell-color-scripts/colorscript.sh -r
#Enable Syntax Highlighting
source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
# Path to your oh-my-zsh installation.
ZSH=/usr/share/oh-my-zsh
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
#ZSH_THEME="theunraveler"
ZSH_THEME="agnoster"
# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in ~/.oh-my-zsh/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )
# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"
# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"
# Uncomment the following line to disable bi-weekly auto-update checks.
DISABLE_AUTO_UPDATE="true"
# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13
# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"
# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"
# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"
# Uncomment the following line to display red dots whilst waiting for completion.
# COMPLETION_WAITING_DOTS="true"
# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"
# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"
# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder
# Which plugins would you like to load?
# Standard plugins can be found in ~/.oh-my-zsh/plugins/*
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(
git
)
# User configuration
# export MANPATH="/usr/local/man:$MANPATH"
# You may need to manually set your language environment
# export LANG=en_US.UTF-8
# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
# export EDITOR='vim'
# else
# export EDITOR='mvim'
# fi
# Compilation flags
# export ARCHFLAGS="-arch x86_64"
# ssh
# export SSH_KEY_PATH="~/.ssh/rsa_id"
# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
ZSH_CACHE_DIR=$HOME/.cache/oh-my-zsh
if [[ ! -d $ZSH_CACHE_DIR ]]; then
mkdir $ZSH_CACHE_DIR
fi
source $ZSH/oh-my-zsh.sh
# Creates an archive (*.tar.gz) from given directory.
function maketar() { tar cvzf "${1%%/}.tar.gz" "${1%%/}/"; }
# Create a ZIP archive of a file or folder.
function makezip() { zip -r "${1%%/}.zip" "$1" ; }
# Function extract for common file formats
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
function extract {
if [ -z "$1" ]; then
# display usage if no parameters given
echo "Usage: extract <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>"
echo " extract <path/file_name_1.ext> [path/file_name_2.ext] [path/file_name_3.ext]"
else
for n in "$@"
do
if [ -f "$n" ] ; then
case "${n%,}" in
*.cbt|*.tar.bz2|*.tar.gz|*.tar.xz|*.tbz2|*.tgz|*.txz|*.tar)
tar xvf "$n" ;;
*.lzma) unlzma ./"$n" ;;
*.bz2) bunzip2 ./"$n" ;;
*.cbr|*.rar) unrar x -ad ./"$n" ;;
*.gz) gunzip ./"$n" ;;
*.cbz|*.epub|*.zip) unzip ./"$n" ;;
*.z) uncompress ./"$n" ;;
*.7z|*.arj|*.cab|*.cb7|*.chm|*.deb|*.dmg|*.iso|*.lzh|*.msi|*.pkg|*.rpm|*.udf|*.wim|*.xar)
7z x ./"$n" ;;
*.xz) unxz ./"$n" ;;
*.exe) cabextract ./"$n" ;;
*.cpio) cpio -id < ./"$n" ;;
*.cba|*.ace) unace x ./"$n" ;;
*)
echo "extract: '$n' - unknown archive method"
return 1
;;
esac
else
echo "'$n' - file does not exist"
return 1
fi
done
fi
}
IFS=$SAVEIFS
# jump directorys upwards until it hits a directory with multiple folders
up(){
local d=""
limit=$1
for ((i=1 ; i <= limit ; i++))
do
d=$d/..
done
d=$(echo $d | sed 's/^\///')
if [ -z "$d" ]; then
d=..
fi
cd $d
}
# create a directory and directly cd into it
mkcd () {
mkdir -p $1
cd $1
}
#file upload
transfer() {
# check arguments
if [ $# -ne 1 ];
then
echo -e "Wrong arguments specified. Usage:\ntransfer /tmp/test.md\ncat /tmp/test.md | transfer test.md"
return 1
fi
# get temporary filename, output is written to this file so show progress can be showed
tmpfile="$( mktemp -t transferXXX )"
# upload stdin or file
file="$1"
if tty -s;
then
basefile="$( basename "$file" | sed -e 's/[^a-zA-Z0-9._-]/-/g' )"
if [ ! -e $file ];
then
echo "File $file doesn't exists."
return 1
fi
if [ -d $file ];
then
# zip directory and transfer
zipfile="$( mktemp -t transferXXX.zip )"
cd "$(dirname "$file")" && zip -r -q - "$(basename "$file")" >> "$zipfile"
curl --progress-bar --upload-file "$zipfile" "https://transfer.sh/$basefile.zip" >> "$tmpfile"
rm -f $zipfile
else
# transfer file
curl --progress-bar --upload-file "$file" "https://transfer.sh/$basefile" >> "$tmpfile"
fi
else
# transfer pipe
curl --progress-bar --upload-file "-" "https://transfer.sh/$file" >> "$tmpfile"
fi
# cat output link
cat "$tmpfile"
echo
# cleanup
rm -f "$tmpfile"
}
#ix pastebin service
ix() {
local opts
local OPTIND
[ -f "$HOME/.netrc" ] && opts='-n'
while getopts ":hd:i:n:" x; do
case $x in
h) echo "ix [-d ID] [-i ID] [-n N] [opts]"; return;;
d) $echo curl $opts -X DELETE ix.io/$OPTARG; return;;
i) opts="$opts -X PUT"; local id="$OPTARG";;
n) opts="$opts -F read:1=$OPTARG";;
esac
done
shift $(($OPTIND - 1))
[ -t 0 ] && {
local filename="$1"
shift
[ "$filename" ] && {
curl $opts -F f:1=@"$filename" $* ix.io/$id
return
}
echo "^C to cancel, ^D to send."
}
curl $opts -F f:1='<-' $* ix.io/$id
}
# make a backup of a file
bk() {
cp -a "$1" "${1}_$(date --iso-8601=seconds)"
}
#Alias
alias cls="clear"
alias cd=' cd'
alias ..=' cd ..; ls'
alias ...=' cd ..; cd ..; ls'
alias ....=' cd ..; cd ..; cd ..; ls'
alias cd..='..'
alias cd...='...'
alias cd....='....'
#alias ls="ls -CF --color=auto"
alias ls="exa --long"
alias ll="ls -lisa --color=auto"
alias lsl="ls -lhFA | less"
# display the ten newest files
alias lsnew="ls -rl *(D.om[1,10])"
# display the ten oldest files
alias lsold="ls -rtlh *(D.om[1,10])"
# display the ten smallest files
alias lssmall="ls -Srl *(.oL[1,10])"
alias home="cd ~"
alias df="df -ahiT --total"
alias mkdir="mkdir -pv"
alias userlist="cut -d: -f1 /etc/passwd"
alias fhere="find . -name "
alias free="free -mt"
alias du="du -ach | sort -h"
alias ps="ps auxf"
alias psgrep="ps aux | grep -v grep | grep -i -e VSZ -e"
alias wget="wget -c"
alias histg="history | grep"
alias myip="curl http://ipecho.net/plain; echo"
alias logs="find /var/log -type f -exec file {} \; | grep 'text' | cut -d' ' -f1 | sed -e's/:$//g' | grep -v '[0-9]$' | xargs tail -f"
alias folders='find . -maxdepth 1 -type d -print0 | xargs -0 du -sk | sort -rn'
alias grep='grep --color=auto'
alias dpaste="curl -F 'format=url' -F 'content=<-' https://dpaste.de/api/"
alias rm="rm -i"
# package management Arch
# default action - install one or more packages
alias pac="sudo pacman -S"
# '[u]pdate' - upgrade all packages to their newest version
alias pacu="sudo pacman -Syu"
# '[s]earch' - search for a package using one or more keywords
alias pacs="pacman -Ss"
# '[i]nfo' - show information about a package
alias paci="sudo pacman -Si"
# '[r]emove' - uninstall one or more packages
alias pacr="sudo pacman -R"
# '[p]urge' - purge a package + config files
alias pacp="sudo pacman -Rns"
# '[l]ist' - list all packages of a repository
alias pacl="sudo pacman -Sl"
# '[l]ist [l]ocal' - list all packages which were locally installed (e.g. AUR packages)
alias pacll="sudo pacman -Qqm"
# '[l]ist [o]rphans' - list all packages which are orphaned
alias paclo="sudo pacman -Qdt"
# '[o]wner' - determine which package owns a given file
alias paco="sudo pacman -Qo"
# '[f]iles' - list all files installed by a given package
alias pacf="sudo pacman -Ql"
# '[c]lean cache' - delete all not currently installed package files
alias pacc="sudo pacman -Sc"
# '[m]ake' - make package from PKGBUILD file in current directory
alias pacm="makepkg -fci"
# [in]stall -install local package
alias pacin="sudo pacman -U"
#Tracking unowned files created by packages
alias pacreportuo="sudo pacreport --unowned-files"
#Listing changed backup files
alias pacmanchanged="pacman -Qii | awk '/^MODIFIED/ {print $2}'"
#Remove unneded packages
alias pacclean="pacman -Rsn $(pacman -Qdtq)"
#refresh mirrorlist
alias pacmsync="reflector --verbose --latest 5 --sort rate --save /etc/pacman.d/mirrorlist"
# package management Debian
alias a='apt'
alias ai='apt install'
alias as='apt search'
alias ass='apt show'
alias au='apt update'
alias asu='apt safe-upgrade'
alias afu='apt-file update'
alias afs='apt-file search'
alias afsl='apt-file -l search'
# Clean Debian packages
apt-clean() {
sudo apt-get clean
sudo apt-get autoclean
sudo apt-get autoremove
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment