<aside> 💡 Frequently Used Commands & More Contents.

</aside>

https://www.youtube.com/watch?v=o8NPllzkFhE

Command Lines

Remove line from files recursively based on match

find . -type f -exec sed -i '/string/d' {} \\;

Replace string in all files recursively based on match

find . -type f -exec sed -i 's/string1/string2/g' '{}' \\;

Cleanup Template Files (or others accordingly with your find params)

find . -name *.html.php | xargs rm -rf

Git v2.21.0: Download && Extract && Compile && Install

cd /usr/src
wget <https://www.kernel.org/pub/software/scm/git/git-2.21.0.tar.gz> --no-check-certificate
tar xzf git-2.21.0.tar.gz
cd git-2.21.0
perl -pi -e 's/^#~\\|.*\\n//' po/fr.po
make prefix=/usr/local/git all
make prefix=/usr/local/git install
echo "export PATH=/usr/local/git/bin:$PATH" >> /etc/bashrc
source /etc/bashrc
git --version

Unuseful Aliases & Functions

Get git branch name on terminal (Used with 'PS1=' to attach to the folder/session name)

# If something weird is happening check: 
# <https://unix.stackexchange.com/questions/28827/why-is-my-bash-prompt-getting-bugged-when-i-browse-the-history>

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

# Check if is a git repo
is_git_repo() {
  git rev-parse --is-inside-work-tree > /dev/null 2>&1
}

# Get Git project name (basically the root folder of your project)
get_project_name() {
  is_git_repo && basename $(git rev-parse --show-toplevel) || echo ""
}

# Prompt example: [project_folder :: current_folder] (git_branch) >_

# WHEN BASH.. USE PS1 --- I need to check if this is working 100% because now I'm using zsh (after 1000 years haha)
if [ -n "$BASH_VERSION" ]; then
  PS1='\\[\\e[1;32m\\]\\W \\[\\e[0;34m\\]$(parse_git_branch)>_ \\[\\e[0;39m\\]'
  PS1='\\[\\e[32m\\][$(get_project_name) :: \\W] \\[\\e[34m\\]$(parse_git_branch)\\[\\e[0m\\]>_ '
fi

# WHEN ZSH.. USE PROMPT
if [ -n "$ZSH_VERSION" ]; then
  setopt PROMPT_SUBST

  precmd() {
    if [ "$(get_project_name)" != "" ]; then
      PROMPT='%F{green}[$(get_project_name) :: %1d] %F{blue}$(parse_git_branch)%f>_ '
    else
      PROMPT='%F{cyan}%1d %f>_ '
    fi
  }

  setopt no_share_history
  unsetopt share_history
fi

Force the Git Sync (Use at your own risk at Friday 5:50PM) ¯\\*(ツ)*/¯

forcesync() {
    ACTUAL_BRANCH=$(git branch | grep \\* | cut -d ' ' -f2)
    if [ -z "$1" ]
    then
        #Aux to just show me the command
        echo ''
        echo 'Actual Branch: $(ACTUAL_BRANCH)'
        echo 'git fetch origin && git reset --hard origin/{BRANCH} && git clean -fd'
        echo ''
    else
        echo ''
        echo 'Forcing the sync...'
        git fetch origin && git reset --hard origin/$1 && git clean -fd
        echo 'Your sync was completed!'
        echo ''
    fi
}

Some of my aliases

# findh == Find Here
alias findh='find ./ -name'
alias checkdistro='cat /etc/*-release'

# Shortcut to recursive grep without git and svn folders
alias grep='grep --exclude-dir={".svn",".git","node_modules"}'
alias ngrep='grep -rn ./ -e'

# Clean PHP Smarty Cache
alias clean_cache='find . -name *.html.php | xargs rm -rf'

# Show the command to replace a content on multiple files
alias replacer='echo "find <mydir> -type f -exec sed -i '"'"'s'"/"'<String1>'"/"'<String2>'"/"'g'"'"' {} +"'

##
# ALIAS | GIT
##
alias amend='git commit --amend --no-edit'
alias this="git branch | grep \\* | cut -d ' ' -f2"
pull() {
    echo 'Stashing...'
    git stash
    echo 'Pulling...'
    git pull --rebase
    echo 'Stash pop...'
    git stash pop
    echo 'Done~'
}

# Add a filepath to .git/info/exclude
localIgnore() {
    echo "$1" >> .git/info/exclude
    echo "File $1 locally ignored"
    echo ""
    echo "---- .git/info/exclude ----"
    cat .git/info/exclude
    echo "---- ----------------- ----"
    echo ""
}

Wanna more from git?? Look at: