Make Your Linux Terminal Enjoyable to Use
source link: https://dev.to/dhupee/make-your-linux-terminal-enjoyable-to-use-3j47
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
At some point, we as Linux users or even Mac need to use a terminal at some point, whether to install something or do a software engineer task, or whatever it is. but you know, the terminal is boring and often becomes the main point of why people are afraid of Linux in general.
"Oh oh, it's scary, it's hard to use, I don't know these commands and stuff"
No more scared of terminals or using boring terminals that are a pain to use
I can't help with the scary commands because I think that's something that we need to learn along the way, but I guess I can help to make it a bit more bearable.
Okay, let's go!
Warning: this stuff needs quite a bit of resources compared to your stock one of course, so if your PC is a real potato you might want to back off a little bit I'm sorry
Ditch Bash to Use ZSH
Dont uninstall of course are you crazy? just add a new shell for your computer, we are going to install zsh
to enable us to add fancy toys.
Mac users rejoice because iirc you guys have it by default
first, the installation is like the usual in your terminal, I use an Arch-based Linux distro, so it is going to be
sudo pacman -S zsh
If your shell doesn't change to zsh, type zsh
then you should have something like this, standard zsh.
OH...MY...ZSH!!
After this you going to visit Oh-My-Zsh which is where the magic will happen.
Oh My Zsh is an open-source, community-driven framework for managing your zsh configuration.
To install it you can use curl, wget, or fetch. I usually go with curl, so it's simply
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
After that, it will do its thing like moving your old zshrc to zshrc.pre-oh-my-zsh or some other thing but then you can have your zsh ready to go, and looks good.
you can check around the documentation, change the theme, add provided plugins on to your zshrc.
Custom Plugins
This is gonna be the main sauce, custom plugins, personally, I have 4 installed on my setup.
Syntax highlighting
This one helps you to syntax highlight your shell commands, giving clarity, and maybe help spot mistakes like missing quote opening.
git clone --depth 1 "https://github.com/zsh-users/zsh-syntax-highlighting.git" $HOME/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting
Auto Suggestion
This is different from autocomplete since it suggests based on your previous commands, quicker if you want to use the command you used before
git clone --depth 1 "https://github.com/zsh-users/zsh-autosuggestions.git" $HOME/.oh-my-zsh/custom/plugins/zsh-autosuggestions
Autocomplete
This one is probably still underutilized in my end but it's simply the most powerful plugin there
git clone --depth 1 "https://github.com/marlonrichert/zsh-autocomplete.git" $HOME/.oh-my-zsh/custom/plugins/zsh-autocomplete
History Substring Search
This is quite difficult to explain, the best I can explain is I can type git
then I press up-arrow then it going to present me with my history git command I do, I use it extensively when I want to make a script or documentation.
git clone --depth 1 "https://github.com/zsh-users/zsh-history-substring-search" $HOME/.oh-my-zsh/custom/plugins/zsh-history-substring-search
Custom theme
This one is not needed if you already like the theme they have, but if you like me who I WANT MORE!! You can use powerlevel10k
This one is like a framework by itself so I will leave the git repo instead https://github.com/romkatv/powerlevel10k?tab=readme-ov-file
KABLAM!
There's more??
To be honest, we can go more, but some of this needs us to use a terminal often
"Alias" for example, is just a bunch of commands that we use often but too long, so we make short and easy-to-remember aliases so we can reduce our type or just make it easy to remember
These are some of the popular aliases there, provided excellently by Marius Colacioiu
Intro
Bellow follows a list of aliases, split between beginner and advanced.
To start using them right away you should place the aliases you like most in a file like ~/.zsh/git
. Now all that remains is to add the following line to your ~/.zshrc
or ~/.bashrc
:
. ~/.zsh/git # git aliases
Git aliases: beginner
# Most used git command should be short.
alias s='git status -sb'
alias ga='git add -A'
alias gap='ga -p'
alias gbr='git branch -v'
gc() {
git diff --cached | grep '\btap[ph]\b' >/dev/null &&
echo "\e[0;31;29mOops, there's a #tapp or similar in that diff.\e[0m" ||
git commit -v "$@"
}
alias gch='git cherry-pick'
alias gcm='git commit -v --amend'
alias gco='git checkout'
alias gd='git diff -M'
alias gd.='git diff -M --color-words="."'
alias gdc='git diff --cached -M'
alias gdc.='git diff --cached -M --color-words="."'
alias gf='git fetch'
# Helper function.
git_current_branch() {
cat "$(git rev-parse --git-dir 2>/dev/null)/HEAD" | sed -e 's/^.*refs\/heads\///'
}
alias glog='git log --date-order --pretty="format:%C(yellow)%h%Cblue%d%Creset %s %C(white) %an, %ar%Creset"'
alias gl='glog --graph'
alias gla='gl --all'
alias gm='git merge --no-ff'
alias gmf='git merge --ff-only'
alias gp='git push'
alias gpthis='gp origin $(git_current_branch)'
alias gpthis!='gp --set-upstream origin $(git_current_branch)'
alias grb='git rebase -p'
alias grba='git rebase --abort'
alias grbc='git rebase --continue'
alias grbi='git rebase -i'
alias gr='git reset'
alias grh='git reset --hard'
alias grsh='git reset --soft HEAD~'
alias grv='git remote -v'
alias gs='git show'
alias gs.='git show --color-words="."'
alias gst='git stash'
alias gstp='git stash pop'
alias gup='git pull'
Git aliases: advanced
# Use gh instead of git (fast GitHub command line client).
#
# More info: https://github.com/jingweno/gh
#
if type gh >/dev/null; then
alias git=gh
if type compdef >/dev/null 2>/dev/null; then
compdef gh=git
fi
fi
# Redefine alias. Allow to pass more args to `s`.
s() {
git status -sb "$@"
return 0
}
git-new() {
[ -d "$1" ] || mkdir "$1" &&
cd "$1" &&
git init &&
touch .gitignore &&
git add .gitignore &&
git commit -m "Add .gitignore."
}
# Query `glog` with regex query.
gls() {
query="$1"
shift
glog --pickaxe-regex "-S$query" "$@"
}
# Checkout git-smart gem for more infos.
#
# More infos: https://github.com/geelen/git-smart
#
alias gup='git smart-pull'
# Create your own git alias, reusing other git shortcuts.
alias gpstaging='export PREVIOUS_BRANCH=$(git_current_branch) ; gco -B staging ; gpthis -f ; gco $PREVIOUS_BRANCH ; gbr -D staging'
# Create pull-request from command line (uses gh gem).
alias gpr='gpthis; git pull-request'
Credits
The way I use git changed since I found and started using benhoskings's dot-files. Using all those aliases for git commands started to grow on me, day after day.
Recommended video: Ben Hoskings on Advanced Git.
This one is mine, saved as .aliases.sh then sourced it on my zshrc
What else??
What else we can add?? I guess it depends on our imagination no? Let me know in the comments what can I add here.
Cheers
EDIT: adding credit to the gist provider
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK