Skip to content

Instantly share code, notes, and snippets.

@kidager
Last active January 16, 2023 17:03
Show Gist options
  • Save kidager/55f74e05d387d98bcda4bd7783954a5d to your computer and use it in GitHub Desktop.
Save kidager/55f74e05d387d98bcda4bd7783954a5d to your computer and use it in GitHub Desktop.
ZSH Powerline installation
# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
ZSH_THEME="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.
# The optional three formats: "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# 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? (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 composer laravel npm branch command-not-found common-aliases cp github gitignore nmap pip sudo perms docker)
# User configuration
# export PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
# export MANPATH="/usr/local/man:$MANPATH"
source $ZSH/oh-my-zsh.sh
# 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='nano'
else
export EDITOR='nano'
fi
# Compilation flags
# export ARCHFLAGS="-arch x86_64"
HISTCONTROL=ignoreboth
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=10000
HISTFILESIZE=20000
# 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="$EDITOR ~/.zshrc && . ~/.zshrc"
alias ohmyzsh="$EDITOR ~/.oh-my-zsh && . ~/.oh-my-zsh"
# Load global zsh file
source /etc/zsh/zprofile
# Repeat n times command
function repeat() {
local i max
max=$1; shift;
for ((i=1; i <= max ; i++)); do # --> C-like syntax
eval "$@";
done
}
# Mkdir with CD directly
function mkdircd () { mkdir -p "$@" && eval cd "\"\$$#\""; }
# 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" ; }
# Make your directories and files access rights sane.
function sanitize() { chmod -R u=rwX,g=rX,o= "$@" ;}
# Add easy extract support
function extract () {
if [ -f $1 ]; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.tar.xz) tar Jxvf $1 ;;
*.lzma) unlzma $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xvf $1 ;;
*.tbz2) tar xvjf $1 ;;
*.tgz) tar xvzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*.xz) unxz $1 ;;
*.exe) cabextract $1 ;;
*) echo "don't know how to extract '$1'..." ;;
esac
else
echo "'$1' is not a valid file!"
fi
}
# Function to run upon exit of shell.
#function _exit() {
# echo -e "Hasta la vista, baby"
# echo -e "\e[1;5;32m ____ \e[0m"
# echo -e "\e[1;5;32m | __ ) _ _ ___ \e[0m"
# echo -e "\e[1;5;32m | _ \| | | |/ _ \\e[0m"
# echo -e "\e[1;5;32m | |_) | |_| | __/\e[0m"
# echo -e "\e[1;5;32m |____/ \__, |\___|\e[0m"
# echo -e "\e[1;5;32m |___/ \e[0m"
# sleep 0.75
#}
#trap _exit EXIT
# Find a file with a pattern in name:
function ff() { find . -type f -iname '*'"$*"'*' -ls ; }
alias hibernate='systemctl hibernate'
# if user is not root, pass all these commands via sudo #
if [ $UID -ne 0 ]; then
alias reboot='sudo /sbin/reboot'
alias poweroff='sudo /sbin/poweroff'
alias halt='sudo /sbin/halt'
alias shutdown='sudo /sbin/shutdown'
alias hibernate='sudo systemctl hibernate'
alias apt-get='sudo apt-get'
fi
# Make life easier
alias aptget='apt-get'
alias rm='rm -I'
alias rmrf='rm -rf'
# some more ls aliases
alias diskspace='du -S | sort -n -r | more'
alias folders='find . -maxdepth 1 -type d -print | xargs du -sk | sort -rn'
alias mkdir='mkdir -pv'
alias c='clear'
alias cls='clear'
alias copy='cp'
alias rename='mv'
alias del='rm'
alias install='apt-get install'
alias fuck='echo -e "Chill out man, nothing is worth being upset\n\nHere is a quote, read it:\n`fortune`"'
alias now='date +"%T'
alias nowtime=now
alias nowdate='date +"%d-%m-%Y"'
alias push='git push -v'
alias ping='ping -c 5'
alias pingfast='ping -c 100 -s.2'
alias ports='netstat -tulanp'
alias wget='wget -c'
alias top='htop'
alias meminfo='free -m -l -t'
alias cpuinfo='lscpu'
alias cpuinfoold='less /proc/cpuinfo'
alias gpumeminfo='grep -i --color memory /var/log/Xorg.0.log'
## get top process eating memory
alias psmem='ps auxf | sort -nr -k 4'
alias psmem10='ps auxf | sort -nr -k 4 | head -10'
## get top process eating cpu ##
alias pscpu='ps auxf | sort -nr -k 3'
alias pscpu10='ps auxf | sort -nr -k 3 | head -10'
alias more='less'
alias ll='ls -l'
alias lla='ll -a'
alias llh='ll -h'
alias llm='ll | \more'
alias lll='ll | \less'
alias llr='ll -R'
alias la='ls -A'
alias l='ls -CF'
alias l.='ls -d .* --color=auto'
alias artisan='php artisan'
alias ..='cd ..'
alias s='cd ..'
alias please='sudo'
alias comeon='sudo $(history -p !!)'
alias sob=ll
alias het=ll
alias chfama=ll
alias lista=ll
alias damn='echo "Relax, man!"'
alias pull='git pull'
alias fire='git checkout -b firealert_$(date +"%d_%m_%Y-%H_%M_%S") && git add -f --all && git commit -f -m "Fire alert" && git push -f'
#!/bin/bash
# If not run as root, then exit here
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
# main settings
TMP_DIR=$(date +%s | md5sum | head -c 32)
TMP_DIR="/tmp/$TMP_DIR"
#CONFIG_FILE="~/.zshrc"
CONFIG_FILE="/etc/zsh/zshrc"
ZSH_PROFILE="/etc/zsh/zprofile"
FONTS_DIR="/usr/share/fonts"
LOG_FILE="./install-zsh-powerline.log"
# Perform a repo update
apt-get update
# Install wget
echo "Installing wget..."
apt-get -y install wget 1>"$LOG_FILE" 2>&1
# Install dos2unix
echo "Installing dos2unix..."
apt-get -y install dos2unix 1>"$LOG_FILE" 2>&1
# Install git
echo "Installing git..."
apt-get -y install git git-core 1>"$LOG_FILE" 2>&1
# Install zsh
echo "Installing zsh..."
apt-get -y install zsh zsh-common 1>"$LOG_FILE" 2>&1
# Install pip3
echo "Installing pip3..."
apt-get -y install python3-pip 1>"$LOG_FILE" 2>&1
# Install oh-my-zsh
echo "Installing Oh-My-Zsh..."
wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | dos2unix | zsh
echo "Adding aliases loading to zsh profile..."
echo "# Alias definitions." >> $ZSH_PROFILE
echo "# You may want to put all your additions into a separate file like" >> $ZSH_PROFILE
echo "# ~/.zsh_aliases, instead of adding them here directly." >> $ZSH_PROFILE
echo "if [ -f ~/.zshaliases ]; then" >> $ZSH_PROFILE
echo " . ~/.zshaliases" >> $ZSH_PROFILE
echo "fi" >> $ZSH_PROFILE
echo "if [ -f /etc/zsh/zshaliases.zshrc ]; then" >> $ZSH_PROFILE
echo " . /etc/zsh/zshaliases.zshrc" >> $ZSH_PROFILE
echo "fi" >> $ZSH_PROFILE
echo "Adding personal aliases to zsh profile..."
if [ ! -f "/etc/zsh/zshaliases.zshrc" ]; then
wget "https://gist.githubusercontent.com/kidager/55f74e05d387d98bcda4bd7783954a5d/raw/d0a804de7dd279a009484909d18d55a087a02c2f/aliases.sh" -O - >> "/etc/zsh/zshaliases.zshrc"
fi;
dos2unix /etc/zsh/zshaliases.zshrc
echo "Downloading personal zsh configuration..."
if [ -f "$HOME/.zshrc" ]; then
mv "$HOME/.zshrc" "$HOME/.zshrc.bak"
fi;
wget "https://gist.githubusercontent.com/kidager/55f74e05d387d98bcda4bd7783954a5d/raw/d0a804de7dd279a009484909d18d55a087a02c2f/.zshrc" -O - | dos2unix > "$HOME/.zshrc"
# Set zsh as default shell
echo "Setting zsh as default shell..."
chsh -s $(which zsh) 1>"$LOG_FILE" 2>&1
# Install powerline
echo "Installing powerline..."
pip3 install powerline-status 1>"$LOG_FILE" 2>&1
REPO_ROOT=$(pip3 show powerline-status | grep "^Location" | cut -d: -f2 | cut -d" " -f2)
echo "Adding powerline to zsh..."
echo "" >> "$ZSH_PROFILE"
echo "" >> "$ZSH_PROFILE"
echo "# Load powerline" >> "$ZSH_PROFILE"
echo ". $REPO_ROOT/powerline/bindings/zsh/powerline.zsh" >> "$ZSH_PROFILE"
echo "" >> "$ZSH_PROFILE"
dos2unix "$ZSH_PROFILE"
# Install Powerline patched font
# You only need this on the client machine
# echo "Installing powerline fonts..."
# wget https://github.com/powerline/powerline/raw/develop/font/PowerlineSymbols.otf -O "$TMP_DIR/PowerlineSymbols.otf"
# wget https://github.com/powerline/powerline/raw/develop/font/10-powerline-symbols.conf -O "$TMP_DIR/10-powerline-symbols.conf"
# mkdir -p "$FONTS_DIR" 1>"$LOG_FILE" 2>&1
# mv "$TMP_DIR/PowerlineSymbols.otf" "$FONTS_DIR" 1>"$LOG_FILE" 2>&1
# fc-cache -vf "$FONTS_DIR" 1>"$LOG_FILE" 2>&1
# mkdir -p "/etc/fonts/conf.d" 1>"$LOG_FILE" 2>&1
# mv "$TMP_DIR/10-powerline-symbols.conf" "/etc/fonts/conf.d" 1>"$LOG_FILE" 2>&1
echo ""
echo ""
echo "--------------------------------------------------------------"
echo "- Installation complete, please set your theme to 'agnoster' -"
echo "- Please run 'chsh -s $(which zsh)' to set zsh as default -"
echo "--------------------------------------------------------------"
@LastCleanShirt
Copy link

nice thanks!~

@SimZhou
Copy link

SimZhou commented May 23, 2022

alias fuck='echo -e "Chill out man, nothing is worth being upset\n\nHere is a quote, read it:\n`fortune`"'

laughing my ass off :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment