Skip to content

Instantly share code, notes, and snippets.

@mkuchak
Last active September 23, 2021 19:59
Show Gist options
  • Save mkuchak/eccf60a4b62545bea0456c1ba6380578 to your computer and use it in GitHub Desktop.
Save mkuchak/eccf60a4b62545bea0456c1ba6380578 to your computer and use it in GitHub Desktop.
Terminal Hyper and ZSH configuration with Git shortcuts bonus

Hyper + ZSH + Git

Terminal Hyper and ZSH configuration with Git shortcuts bonus.

1. Installing Hyper

  1. Download Debian version on Hyper Terminal
  2. To change default terminal on Ctrl + Alt + T shortcut, run this command
sudo update-alternatives --install /usr/bin/x-terminal-emulator x-terminal-emulator /opt/Hyper/hyper 50
  1. Open Omni Theme and install
git clone https://github.com/getomni/hyper-omni ~/.hyper_plugins/local/hyper-omni
  1. Press Ctrl + Comma and configure hyper
  2. On local plugins set
// to load it and avoid it being `npm install`ed
localPlugins: ["hyper-omni"],
  1. Download and install Operator Mono Lig font.
  2. On font family set
// font family with optional fallbacks
fontFamily:
  '"Operator Mono Lig", Menlo, "DejaVu Sans Mono", Consolas, "Lucida Console", monospace',
  1. Install some plugins
hyper i hyper-fading-scrollbar
hyper i hypercwd
hyper i hyper-pane

2. Installing ZSH

  1. Install ZSH and Curl
sudo apt install zsh -y && sudo apt install curl -y
  1. From Oh My Zsh run
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
  1. Will be asked if transform ZSH as default shell, say yes
  2. From Zinit run
sh -c "$(curl -fsSL https://raw.githubusercontent.com/zdharma/zinit/master/doc/install.sh)"
  1. Will be asked if want to install some default plugins, say no
  2. From Spaceship run
git clone https://github.com/denysdovhan/spaceship-prompt.git "$ZSH_CUSTOM/themes/spaceship-prompt" --depth=1
ln -s "$ZSH_CUSTOM/themes/spaceship-prompt/spaceship.zsh-theme" "$ZSH_CUSTOM/themes/spaceship.zsh-theme" 
  1. Edit ZSH source file
code ~/.zshrc
  1. Edit theme
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="spaceship"
  1. Add Plugins on the last line
# Plugins
zinit light zsh-users/zsh-autosuggestions
zinit light zsh-users/zsh-completions
zinit light zdharma/fast-syntax-highlighting
  1. Add theme options
# Theme
LS_COLORS=$LS_COLORS:'ow=01;34:' ; export LS_COLORS
 
SPACESHIP_PROMPT_ORDER=(
  user          # Username section
  dir           # Current directory section
  host          # Hostname section
  git           # Git section (git_branch + git_status)
  hg            # Mercurial section (hg_branch  + hg_status)
  exec_time     # Execution time
  line_sep      # Line break
  vi_mode       # Vi-mode indicator
  jobs          # Background jobs indicator
  exit_code     # Exit code section
  char          # Prompt character
)
 
SPACESHIP_USER_SHOW="always" # Shows System user name before directory name
 
SPACESHIP_PROMPT_ADD_NEWLINE=false
# SPACESHIP_PROMPT_SEPARATE_LINE=false # Make the prompt span across two lines
# SPACESHIP_DIR_TRUNC=1 # Shows only the last directory folder name
 
SPACESHIP_CHAR_SYMBOL=""
SPACESHIP_CHAR_SUFFIX=" "
  1. Hide % on start for Hyper Terminal
# Hide % on start
unsetopt PROMPT_SP
  1. Yarn and Android SDK paths (optional)
# Yarn Global Package Setup
export PATH="$PATH:$(yarn global bin)"

# Android SDK
export ANDROID_HOME=~/android/sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools

# Apply global scripts from ~/home/bin
export PATH=$HOME/bin:/usr/local/bin:$PATH
  1. Force ZSH to be default shell
chsh -s $(which zsh)
  1. Edit ZProfile source file
code /etc/zsh/zprofile
  1. Add lines to load Snapcraft apps with ZSH
# Global Order: zshenv, zprofile, zshrc, zlogin

emulate sh -c 'source /etc/profile'
emulate sh -c 'source /etc/profile.d/apps-bin-path.sh'
  1. Restart computer

3. Installing Git shortcuts

  1. Edit ZSH source file
code ~/.zshrc
  1. On the end of the file copy and paste
# Active to move hidden files
alias dot="setopt -s glob_dots"
alias ll="ls -lah"

# Sys configuration
alias repoconfig="sudo nano /etc/apt/sources.list"
alias zshconfig="nano ~/.zshrc && source ~/.zshrc"
alias zshsource="source ~/.zshrc"
alias ohmyzsh="nano ~/.oh-my-zsh"

# WSL aliases
# alias db="cd /mnt/c/Users/mkuch/Dropbox"
# alias ws="cd /mnt/d/Workspaces"
# alias ~ws="cd /home/mkuchak/Workspaces"
# alias open="explorer.exe"

# WSL fix terminal ctrl
bindkey -e
bindkey '^H' backward-kill-word # Control + backspace
bindkey ";5C" forward-word # Control + arrows
bindkey ";5D" backward-word
# bind '"\C-H":backward-kill-word' # Bash fix

# Linux aliases
alias ws="cd ~/Workspaces"
alias dw="cd ~/Downloads"
alias pc="cd ~/Pictures"
alias vd="cd ~/Videos"
alias dm="cd ~/Documents"
alias ms="cd ~/Music"
alias dk="cd ~/Desktop"
alias open="dolphin"
alias ssh="ssh -o ServerAliveInterval=60"
alias ssh-reset="ssh-keygen -R"
alias nid="npm install -D"
alias nis="npm install -S"
alias nig="sudo npm install -g"
alias nug="sudo npm uninstall -g"
alias ni="npm install"
alias nu="npm uninstall"
alias nr="npm run"

# sitespeed.io
alias ssio='ssio'
function ssio() {
  if [ $# -eq 0 ]; then
    echo "cd ~/sitespeed-result";
    cd ~/sitespeed-result;
  else
    if [ "$1" = "." ]; then
      dolphin ~/sitespeed-result
    elif [[ "$1" =~ .*http.* ]]; then
      echo "sudo docker run --rm -v "$(echo $HOME):/sitespeed.io" sitespeedio/sitespeed.io:15.4.0 $1";
      sudo docker run --rm -v "$(echo $HOME):/sitespeed.io" sitespeedio/sitespeed.io:15.4.0 $1;
    else
      echo "sudo docker run --rm -v "$(echo $HOME):/sitespeed.io" sitespeedio/sitespeed.io:15.4.0 https://$1";
      sudo docker run --rm -v "$(echo $HOME):/sitespeed.io" sitespeedio/sitespeed.io:15.4.0 https://$1;
    fi
  fi
}

# Docker
alias dc="docker-compose" # Docker-compose shortcut as 'dc'
alias dc-rebuild="dc down -v --remove-orphans; dc build --force-rm --no-cache; dc up -d" # Default docker-compose rebuild
alias d="docker" # Docker shortcut as 'd'
alias d-stop="sudo docker stop $(sudo docker ps -a -q)" # Stop all containers
alias d-restart="sudo docker restart $(sudo docker ps -q)" # Restart all containers
alias d-reset="dockerreset" # Reset the entire docker as if it had been reinstalled
alias d-clear="dockerclear" # Cleans the entire docker without removing the images
function dockerreset() {
  d stop $(d ps -aq);
  d rm -f $(d ps -aq);
  d volume rm -f $(d volume ls -q);
  d network rm $(d network ls -q)
  d rmi -f $(d images -q);
  d system prune -fa --volumes;
  d container prune -f;
  d volume prune -f;
  d network prune -f;
  d image prune -fa;
}
function dockerclear() {
  d stop $(d ps -aq);
  d rm -f $(d ps -aq);
  d volume rm -f $(d volume ls -q);
  d network rm $(d network ls -q)
  d container prune -f;
  d volume prune -f;
  d network prune -f;
}

# Laravel
alias artisan-serve='artisanserve'
function artisanserve() {
  if [ $# -eq 0 ]; then
      echo "sudo php artisan serve --host 0.0.0.0 --port 80";
	    sudo php artisan serve --host 0.0.0.0 --port 80;
  else
      echo "sudo php artisan serve --host 0.0.0.0 --port $1";
      sudo php artisan serve --host 0.0.0.0 --port $1;
  fi
}

# System aliases
alias hib='syshibernate'
alias hibernate='syshibernate'
# https://askubuntu.com/questions/1240123/how-to-enable-hibernate-option-in-ubuntu-20-04
function syshibernate() {
  echo "${YELLOW}ATTENTION, YOU WILL HIBERNATE YOUR COMPUTER!${NC}";
  echo "Are you sure you want to ${RED}hibernate${NC} your computer? (y/N)";
  read REPLY
  if [[ "$REPLY" =~ ^[Yy]$ ]]; then
    sudo systemctl hibernate
  fi
}

# Git commands aliases (nano ~/.zshrc && source ~/.zshrc)
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[0;33m'
NC='\033[0m' # No Color

alias gi='git init'
alias grun='git clean -f -d'
alias gf='git fetch origin'
alias gr='gr'
function gr() {
  echo "Are you sure you want to ${RED}hard reset \"$(git rev-parse --abbrev-ref HEAD)\"${NC} branch? (y/N)";
  read REPLY
  if [[ "$REPLY" =~ ^[Yy]$ ]]; then
    if [ $# -eq 0 ]; then
        echo "git reset --hard origin/$(git rev-parse --abbrev-ref HEAD)";
  	    git reset --hard origin/$(git rev-parse --abbrev-ref HEAD);
    else
        echo "git reset --hard origin/$1";
        git reset --hard origin/$1;
    fi
  fi
}

alias gs='git status'
alias gl='git log'

alias ga='git add .'
alias gaa='git add --all'
alias gc='gc'
function gc() {
  echo "git add . && git commit -am \"$*\"";
  git add . && git commit -am "$*";
}

alias gca='git commit --amend'
alias gcr='git reset --hard'
alias gcrv='gcrv'
function gcrv() {
      echo "Revert the changes specified by the ${RED}$1 last commit${NC} in HEAD and create a new commit with the reverted changes?";
      read REPLY
      if [[ "$REPLY" =~ ^[Yy]$ ]]; then
        echo "git revert HEAD~$1";
        git revert HEAD~$1;
      fi
}

alias gg='gg'
function gg() {
  if [ $# -eq 0 ]; then
      echo "${GREEN}Getting:${NC} git pull origin $(git rev-parse --abbrev-ref HEAD)";
	    git pull origin $(git rev-parse --abbrev-ref HEAD);
  else
      echo "git pull origin $1";
      git pull origin $1;
  fi
}

alias ggf='ggf'
function ggf() {
  if [ $# -eq 0 ]; then
      echo "${GREEN}Getting:${NC} git pull -f origin $(git rev-parse --abbrev-ref HEAD)";
	    git pull -f origin $(git rev-parse --abbrev-ref HEAD);
  else
      echo "git pull -f origin $1";
      git pull -f origin $1;
  fi
}

alias gp='gp'
function gp() {
  if [ $# -eq 0 ]; then
      echo "${BLUE}Putting:${NC} git push origin $(git rev-parse --abbrev-ref HEAD)";
	    git push origin $(git rev-parse --abbrev-ref HEAD);
  else
      echo "git push origin $1";
      git push origin $1;
  fi
}

alias gcp='gcp'
function gcp() {
  echo "${BLUE}Putting:${NC} git add . && git commit -am \"$*\" && git push origin $(git rev-parse --abbrev-ref HEAD)";
  git add . && git commit -am "$*" && git push origin $(git rev-parse --abbrev-ref HEAD);
}

alias gpf='gpf'
function gpf() {
  if [ $# -eq 0 ]; then
      echo "${BLUE}Putting:${NC} git push -f origin $(git rev-parse --abbrev-ref HEAD)";
	    git push -f origin $(git rev-parse --abbrev-ref HEAD);
  else
      echo "git push -f origin $1";
      git push -f origin $1;
  fi
}

alias gb='gb'
function gb() {
  if [ $# -eq 0 ]; then
      echo "git checkout master";
	    git checkout master;
  else
      if [ $# -eq 2 ]; then
        echo "git branch -m $1 $2";
        git branch -m $1 $2;
      else
        echo "git checkout $1";
        git checkout $1;
      fi
  fi
}

alias gbm='gbm'
function gbm() {
  if [ $# -eq 0 ]; then
      echo "Send all commits from ${RED}\"$(git rev-parse --abbrev-ref HEAD)\"${NC} to ${RED}\"master\"${NC}? (y/N)";
      read REPLY
      if [[ "$REPLY" =~ ^[Yy]$ ]]; then
        echo "git merge master $(git rev-parse --abbrev-ref HEAD)";
	      git merge master $(git rev-parse --abbrev-ref HEAD);
      fi
  else
      if [ $# -eq 2 ]; then
        echo "Send all commits from ${RED}\"$1\"${NC} to ${RED}\"$2\"${NC}? (y/N)";
        read REPLY
        if [[ "$REPLY" =~ ^[Yy]$ ]]; then
          echo "git merge $2 $1";
          git merge $2 $1;
        fi
      else
        echo "Receive all commits from ${RED}\"$1\"${NC}? (y/N)";
        read REPLY
        if [[ "$REPLY" =~ ^[Yy]$ ]]; then
          echo "git merge $(git rev-parse --abbrev-ref HEAD) $1";
          git merge $(git rev-parse --abbrev-ref HEAD) $1;
        fi
      fi
  fi
}

alias gbl='echo $(git branch -l) | xargs -n1'
alias gbla='echo $(git branch -a) | xargs -n1'
alias gblr='echo $(git branch -r) | xargs -n1'

alias gbn='git checkout -b'
alias gbno='gbno'
function gbno() {
  echo "git branch $1 origin/$1";
  git branch $1 origin/$1;
  git checkout $1;
}

alias gbd='gbd'
function gbd() {
  echo "${YELLOW}ATTENTION, THIS IS DANGER!${NC}";
  echo "Are you sure you want to ${RED}delete \"$1\"${NC} branch? (y/N)";
  read REPLY
  if [[ "$REPLY" =~ ^[Yy]$ ]]; then
    echo "git checkout master && git branch -D $1";
    git checkout master && git branch -D $1;
  fi
}

alias gbdo='gbdo'
function gbdo() {
  echo "${YELLOW}ATTENTION, THIS IS DANGER! (remote delete)${NC}";
  echo "Are you sure you want to ${RED}delete \"$1\"${NC} remote branch? (y/N)";
  read REPLY
  if [[ "$REPLY" =~ ^[Yy]$ ]]; then
    echo "git push origin --delete $1";
    git push origin --delete $1;
  fi
}

alias gd='gd'
function gd() {
  git diff $1..$2;
}

alias grv='git remote -v'
alias grro='git remote rm origin'
alias grao='grao'
function grao() {
  echo "git remote add origin $1";
  git remote add origin $1;
}

alias gsc='git config credential.helper store'

4. Installing Ubuntu shortcuts to \?|

  1. Run on terminal
sudo apt install xbindkeys xvkbd -y
nano ~/.xbindkeysrc
  1. Copy and paste this commands
"xvkbd -xsendevent -text '\[backslash]'"
    m:0xc + c:24
    Control+Alt + q

"xvkbd -xsendevent -text '?'"
    m:0xc + c:25
    Control+Alt + w

"xvkbd -xsendevent -text '|'"
    m:0xc + c:52
    Control+Alt + z
  1. Then reload keys
xbindkeys -f ~/.xbindkeysrc 

5. Make super user (sudo) without password

  1. Edit user previlege specification
sudo visudo
  1. Change the user (mkuchak) and put the line at end of the file
mkuchak ALL=(ALL) NOPASSWD:ALL

6. Installing QuickTile

  1. Run on terminal
sudo apt install python3 python3-pip python3-setuptools python3-gi python3-xlib python3-dbus gir1.2-glib-2.0 gir1.2-gtk-3.0 gir1.2-wnck-3.0 -y
sudo pip3 install https://github.com/ssokolow/quicktile/archive/master.zip
  1. Edit QuickTile configuration
code ~/.config/quicktile.cfg
  1. Remove all code and paste the below
[general]
cfg_schema = 1
ModMask = <Mod4><Control>
MovementsWrap = True
ColumnCount = 3

[keys]
# Pin window
KP_Enter = always-above

# Move window between screen
KP_0 = maximize
KP_1 = bottom-left
KP_2 = bottom
KP_3 = bottom-right
KP_4 = left
KP_5 = center
KP_6 = right
KP_7 = top-left
KP_8 = top
KP_9 = top-right

# Move window between workspaces
Right = workspace-go-next
Left = workspace-go-prev
Up = workspace-send-prev
Down = workspace-send-next

# Move window without resize
<Shift>KP_1 = move-to-bottom-left
<Shift>KP_2 = move-to-bottom
<Shift>KP_3 = move-to-bottom-right
<Shift>KP_4 = move-to-left
<Shift>KP_5 = move-to-center
<Shift>KP_6 = move-to-right
<Shift>KP_7 = move-to-top-left
<Shift>KP_8 = move-to-top
<Shift>KP_9 = move-to-top-right

# Usual keys
<Shift>V = vertical-maximize
<Shift>H = horizontal-maximize
<Shift>C = move-to-center
  1. On Autostart programs put to launch and run on login "quicktile --daemonize"

7. NPM Global

mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
export PATH=~/.npm-global/bin:$PATH
source ~/.profile

Main commands

Command Action
git init Inicia nova linha do tempo
git branch Cria nova branch
git checkout master Navega entre as branches
git commit -am "description" Envia alterações realizadas
git merge Une branch ao branch ativo
git checkout -b Cria e navega até a nova branch
git push -u origin Envia branch para o Github
git push -f origin Força o envio da branch
git push Envia alterações ao Github
git pull origin master Recebe alterações de outros
git reset --hard origin/<branch_name> Força obter novamente branch
git reset --hard origin/master Força obter novamente master
git log Visualiza commits
git reset --soft 135889dcc8c34ca9541766fabe7d2fc90a024e32 Volta para determinada commit sem alterar os arquivos
git commit --amend Altera a descrição da última commit

Variations

Command Action
git push origin Envia alterações ao Github para um branch específica
git push origin Envia alterações ao Github para um branch específica
git push origin/master --delete Deleta branch no Github
git rm -r Deleta arquivo ou pasta
git checkout -b Cria e navega até a nova branch
git checkout -b origin/master Cria branch a partir da master e navega até ela
git branch Lista todas as branches locais
git branch -a Lista branches locais e no Github
git branch -m Renomeia branch
git branch -D Deleta branch
git push origin -D Deleta branch no Github
git diff <1st branch>..<2nd branch> Compara branches
git config credential.helper store Armazenar credenciais do Github em cache
sudo git config credential.helper store Alterantiva

If have conflit

Command Action
git checkout master -
git branch new-branch-to-save-current-commits -
git fetch --all -
git reset --hard origin/master -

Alternatives

Command Action
git status Informa estado das commits
git add . Adiciona todos os novos arquivos ao branch que se está
git commit -m "description" Faz a commit dos arquivos que já estão sendo monitorados
git show -

Git shortcut commands

Name Command Parameter Action
git init gi n/a Inicia projeto do git com uma nova linha de tempo
git fetch gf n/a Sincroniza repositório local com repositório remoto, sem perder modificações locais
git hard reset gr n/a Reseta repositório local idêntico ao repositório remoto, perdendo modificações locais
git status gs n/a Mostra arquivos alterados e ainda não commitados
git log gl n/a Mostra últimas commits realizadas com descrição e id
git commit ammend gca n/a Permite editar mensagem da última commit através de um editor de texto
git commit reset gcr <commit_id> Retorna para commit específica sem perder modificações locais
git commit gc <message> Adiciona arquivos novos e commita alterações
git commit put gcp <message> Adiciona arquivos novos, commita alterações e envia para repositório remoto
git get gg <branch_name: optional> Obtém repositório remoto; se não houver argumento pega repositório com mesmo nome do atual
git get force ggf <branch_name: optional> Obtém repositório remoto de maneira forçada
git put gp <branch_name: optional> Envia alterações da branch para repositório remoto
git put force gpf <branch_name: optional> Envia alterações da branch para repositório remoto de maneira forçada
git branch cd gb <branch_name: optional> Navega entre as branches
git branch mv gb <branch_name> <branch_rename> Se houver dois argumentos a branch é renomeada
git branch ls local gbl n/a Lista repositórios locais
git branch ls all gbla n/a Lista repositórios locais e remotos
git branch ls remote gblr n/a Lista repositórios remotos
git branch new gbn <branch_name> Cria novo repositório local
git branch new origin gbno <remote_branch_name> Cria novo repositório local a partir de repositório remoto
git branch delete gbd <branch_name> Deleta repositório local
git branch delete origin gbdo <remote_branch_name> Deleta repositório remoto (cuidado!)
git remote add origin grao <repository.git> Começa a sincronizar pasta git local com repositório remoto
git save credentials gsc n/a Salva credenciais de usuário do GitHub
git diff gd <first_branch> <second_branch> Compara duas branches
git add ga n/a Adiciona arquivos novos
git add all gaa n/a Adiciona todos os arquivos novos e excluídos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment