Skip to content

Instantly share code, notes, and snippets.

@Oleksandr-Moik
Last active May 15, 2023 13:03
Show Gist options
  • Save Oleksandr-Moik/bd6889ff7c93b833623c11551721cce3 to your computer and use it in GitHub Desktop.
Save Oleksandr-Moik/bd6889ff7c93b833623c11551721cce3 to your computer and use it in GitHub Desktop.

My collection of shell aliases

Common

alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'

alias mkdir='mkdir -p'
alias rm='rm -rf'

alias cp='xclip' # copy to X clipboard (register *)
alias cps='xclip -sel clip' # copy to system wide clipboard (register +)
alias vp='xclip -o' # output copied content (paste)
alias vps='xclip -o clip' # paste from system wide clipboard (equivalent to `v -selection clipboard`)

alias ip="curl icanhazip.com"
alias localip="ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'"

if type "xdg-open" &> /dev/null; then
    alias open="xdg-open"
fi

# Make screenshot with flameshot gui, for use delay -d
alias fsg='flameshot gui --path /home/oleksandr/Pictures'

# Add an "alert" alias for long running commands.  Use like so:
#   sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'

shell (sh)

alias upd_s="source ~/.bashrc"

alias bashconfig="subl ~/.bashrc"

# same to `take` in zsh
alias mkcd="mkcd"
mkcd() {
    mkdir "$1" -p
    cd "$1"
    pwd
}

zsh

ZSH_THEME="bira"

plugins=(
    git
    zsh-autosuggestions
    extract
    aliases
    common-aliases
    catimg
    copyfile
    copypath
    debian
    # dircycle
    docker
    docker-compose
    encode64
    laravel
    composer
    nvm
)

alias zshconfig="subl ~/.zshrc"
alias ohmyzsh="subl ~/.oh-my-zsh"

alias reloadcli="source $HOME/.zshrc"

GIT

# GIT ALIACES
alias got='git '
alias get='git '
alias gs='git status '
alias ga='git add '
alias gb='git branch'
alias gc='git commit'
alias gd='git diff'
alias go='git checkout '
alias gk='gitk --all&' # install gitk
alias gh='git hist'
alias gac='git add . && git commit -am '

alias gwip='git add . && git commit -am "wip"'
alias nah='git reset --hard;git clean -df'

In additional to git - ~/.gitconfig - global options and configs

[alias]
    co = checkout
    br = branch
    cm = commit
    st = status
    f = fetch
    cl = clone
    # hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
    hist = log --pretty=format:\"%C(cyan)%h %Cgreen%ad%Creset %Cred|%Creset %s%Cgreen%d %C(yellow)[%an]\" --graph --date=short --decorate
    type = cat-file -t
    dump = cat-file -p
    pl = pull
    plo = pull origin
    plod = pull origin dev
    plom = pull origin master
    ps = push
    pso = push origin
    psod = push origin dev
    psom = push origin master
    save = stash save

for some languages

Python

alias py='python3'

Docker

alias d='docker'
alias dc='docker compose'

function dkill() {
    list=$(docker ps -q) 

    if [[ $list ]]; then
        echo $list | xargs -I IMAGE_ID docker stop IMAGE_ID
    else
        echo "no running containers"; 
    fi  
}

npm, node

alias nrw="npm run watch"
alias nrd="npm run dev"
alias nrp="npm run prod"
alias nrb="npm run build"

alias ni="npm install"
alias nu="npm update"

PHP ecosystem

alias php74="/usr/bin/php7.4"
alias php8="/usr/bin/php8.0"

## switch php version
alias sw_php="sudo update-alternatives --config php"

## Shortcuts
alias phpunit='./vendor/bin/phpunit'
alias phpstan='./vendor/bin/phpstan'
alias pint='./vendor/bin/pint'
alias pest='./vendor/bin/pest'

Composer

export COMPOSER_DIR="$HOME/.config/composer/vendor/bin"

alias pcomposer='composer'
alias pcomposer1='composer1'

alias c='composer'
alias ci='composer install'
alias cr='composer require'
alias cu='composer update'
alias cun='composer update && composer normalize' # https://github.com/ergebnis/composer-normalize

alias csu='composer self-update && composer global update'

laravel

more bash aliases from the community - https://laravel-news.com/bash-aliases

artisan

### Artisan
alias pas='php artisan serve'
alias pao='php artisan optimize'
alias pac='php artisan optimize:clear'
alias pam='php artisan migrate'
alias pamr='php artisan migrate:rollback'
alias pamf='php artisan migrate:fresh'
alias pamfs='php artisan migrate:fresh --seed'

alias artisan='php artisan'
alias a='php artisan'

alias tinker='artisan tinker'

complete artisan commands

_artisan()
{
    local arg="${COMP_LINE#php }"

    case "$arg" in
        a*)
            COMP_WORDBREAKS=${COMP_WORDBREAKS//:}
            COMMANDS=`artisan --raw --no-ansi list | sed "s/[[:space:]].*//g"`
            COMPREPLY=(`compgen -W "$COMMANDS" -- "${COMP_WORDS[COMP_CWORD]}"`)
            ;;
        *)
            COMPREPLY=( $(compgen -o default -- "${COMP_WORDS[COMP_CWORD]}") )
            ;;
        esac

    return 0
}

complete -F _artisan artisan
complete -F _artisan a

laravel sail

# Sail
alias sail='[ -f sail ] && bash sail || bash vendor/bin/sail'
alias s='sail'

alias sst='sail stop'
alias sub='sail up -d && sail bash'
alias sb='sail bash'

ide helper

### ide helper
alias ih="artisan ide-helper:generate && artisan ide-helper:meta && artisan ide-helper:models -N"
alias ihm="artisan ide-helper:models -N"

Misc

Prompt

show git branch in prompt

(for basic shell)

parse_git_branch() {
     git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}

example of use

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\W\[\033[1;31m\]$(parse_git_branch)\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\W\$ '
fi

show shorten path for prompt (last folder)

change \w to \W

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\W\[\033[1;31m\]$(parse_git_branch)\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\W\$ '
fi

Bashrc

Full content of the .bashrc file from Ubuntu

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar

# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color|*-256color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
    # We have color support; assume it's compliant with Ecma-48
    # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
    # a case would tend to support setf rather than setaf.)
    color_prompt=yes
    else
    color_prompt=
    fi
fi

parse_git_branch() {
     git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\W\[\033[1;31m\]$(parse_git_branch)\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\W\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
fi

# colored GCC warnings and errors
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'

# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'

# Add an "alert" alias for long running commands.  Use like so:
#   sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi


# Custom user scripts ----------------------------


# Paths --------------
# NVM
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

# Java
export JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"

# Composer
export COMPOSER_DIR="$HOME/.config/composer/vendor/bin"

# Dart
export DART_DIR="/usr/lib/dart/bin"

PATH="$PATH:$COMPOSER_DIR:$DART_DIR:$JAVA_HOME"
@andrey-helldar
Copy link

Composer:

alias ci='composer install'
alias cr='composer require'
alias cu='composer update'
alias cun='composer update && composer normalize'
alias da='composer dumpauto'

alias csu='composer self-update && composer global update'

The composer normalize it's a ergebnis/composer-normalize package

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