avatarSarvsav Sharma

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

7066

Abstract

n-images-1.readmedium.com/v2/resize:fit:800/1rLJEIaLqwF-_KOdn2t8MMA.png"><figcaption></figcaption></figure><p id="695d"><b>CCAT (written in go)</b></p><p id="037b">It is so boring to use the cat command, and difficulty to read the files on remote server. The ccat utility will highlight the syntax for you while reading the file.</p><p id="6869">From boring output:</p><figure id="5ff7"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*msjnZMJqjhtY2p-v"><figcaption></figcaption></figure><p id="da2a">To fancy output:</p><figure id="6c4e"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*QUDyW3heH7IU1k3z"><figcaption></figcaption></figure><p id="e1f4">It can be installed using go and once installed can be set as an alias for cat command. Use the below command to download and for alias.</p><div id="1e0c"><pre><span class="hljs-meta prompt_"> </span><span class="language-bash">go install github.com/owenthereal/ccat</span></pre></div><p id="5957">More details and information about the options can be found on the <a href="https://github.com/owenthereal/ccat">repo homepage</a>.</p><p id="5ffd">Combining <code>ccat</code> with <code>jq</code> or <code>fx</code> , will make it more powerful. Add the below function in your <code>.zshrc</code> or <code>.bashrc</code> file.</p><div id="5076"><pre><span class="hljs-keyword">function</span> catme { filename=(<span class="hljs-built_in">basename</span> -- <span class="hljs-string">"<span class="hljs-variable">1</span>"</span>) extension=<span class="hljs-string">"<span class="hljs-variable">{filename##.}</span>"</span> filename=<span class="hljs-string">"<span class="hljs-variable">${filename%.*}</span>"</span>

<span class="hljs-keyword">case</span> <span class="hljs-string">"<span class="hljs-variable">extension</span>"</span> <span class="hljs-keyword">in</span> <span class="hljs-string">"json"</span>) ccat <span class="hljs-string">"<span class="hljs-variable">1</span>"</span> | jq -C ;; <span class="hljs-string">"md"</span>) glow <span class="hljs-string">"<span class="hljs-variable">1</span>"</span> ;; <span class="hljs-string">"csv"</span>) result=(gum table < <span class="hljs-string">"<span class="hljs-variable">1</span>"</span>) ;; *) bat <span class="hljs-string">"<span class="hljs-variable">1</span>"</span> ;; <span class="hljs-keyword">esac</span> }

<span class="hljs-built_in">alias</span> <span class="hljs-built_in">cat</span>=catme</pre></div><p id="ef2f">The above function can be extended to support multiple extensions.</p><p id="d9f9">Without <code>ccat</code></p><figure id="aa5c"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*DxVzF0GZqw2z38fRuM3nqA.png"><figcaption></figcaption></figure><p id="ca3b">With <code>ccat</code></p><figure id="045d"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*jf8HylzHfM7zPkoUk1CzBg.png"><figcaption></figcaption></figure><p id="fc59">With alias and below function (It prints pretty with colors):</p><figure id="19aa"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*xLsmrhzcLcXAaA46Y7qdRA.png"><figcaption></figcaption></figure><h1 id="fbcb">7. glow from charmbracelet</h1><p id="7fd5">The above function can be extended to handle parsing of <code>README</code> files on terminal. The glow can be added as a file check to it. To install <code>glow</code> on your machine, run the below command:</p><div id="6600"><pre>go install github.com/charmbracelet/glow@latest</pre></div><p id="ee97">I am using a sample readme file to demonstrate the power of glow.</p><p id="bea6">Without glow:</p><figure id="f72b"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*dMWq5qEDLE3wyQY3rQoA_A.png"><figcaption></figcaption></figure><p id="2860">With glow:</p><figure id="c4cf"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*llUHHKb1PqqQzo-ps3ugxw.png"><figcaption></figcaption></figure><h1 id="2837">8. gum — Improve your shell scripts</h1><p id="ebcc"><code>gum</code> is mostly used to write better shell scripts, however I am using it for better reading the <code>csv</code> files in tabular format. It can be installed using below command:</p><div id="aecb"><pre>go install github.com/charmbracelet/gum@latest</pre></div><p id="55c2">csv file without gum</p><figure id="c2af"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*vef_eGgzJ37O6bvALtVHcg.png"><figcaption>Default output from bat</figcaption></figure><p id="d431">csv file with gum</p><figure id="38c9"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*QB3JCasAD3eJkAKfuZV2GQ.png"><figcaption></figcaption></figure><p id="8197">Update the <code>catme</code> function in your .rc file to use <code>gum</code> .</p><h1 id="6aab">9. carbon-cli</h1><p id="dfb0">carbon-now is a very popular website to take screenshots of your code. Now, it can be done using command line too. Install it with below command.</p><div id="ed7b"><pre><span class="hljs-variable"> </span>npm i -g carbon-now-cli</pre></div><p id="b249">And, the screenshots can be taken like this:</p><div id="9cf6"><pre><span class="hljs-variable"> </span>carbon-now filename.js</pre></div><p id="7a61">Result:</p><figure id="24a2"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*Qpoph4t9G6qqjXDX"><figcaption></figcaption></figure><p id="6c2f">More information can be found on the <a href="https://github.com/mixn/carbon-now-cli#installation">project page</a>.</p><h1 id="bac8">10. diff-so-fancy</h1><p id="104d">It feels so difficult to understand the diff between any two files. Not anymore, with usage of diff-so-fancy, reading diff becomes very easy. Installation is as simple as cloning this repo and then putting the diff-so-fancy script in to your PATH. The lib/ directory will need to be kept relative to the core script.</p><p id="251a">Repo link: <a href="https://github.com/so-fancy/diff-so-fancy">so-fancy/diff-so-fancy: Good-lookin’ diffs. Actually… nah… The best-lookin’ diffs. (github.com)</a></p><figure id="80e8"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*7TA1uuwHbBx4zrcJ"><figcaption></figcaption></figure><h1 id="a8ec">11. duf or gdu</h1><h1 id="89d1">duf</h1><p id="4c28">A fancy way of listing disk usage and free. It can be installed using below command.</p><div id="74b9"><pre><span class="hljs-meta prompt_"> </span><span class="language-bash">go install github.com/muesli/duf@latest</span></pre></div><figure id="d34a"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*FOEYT4gYXwCZxYb0"><figcaption></figcaption></figure><h1 id="2bce">gdu</h1><p id="4ed0">du is a disk usage command, and very popular among linux administrator. However, with missing features like no updates on progress, it is difficult to use. To make the output for fancy, there is a tool written in go named gdu can be used. The installation is very simple, and can be done using below command.</p><div id="7f8f"><pre><span class="hljs-meta prompt_">$ </spa

Options

n><span class="language-bash">go install github.com/dundee/gdu/v5/cmd/gdu@latest</span></pre></div><p id="b142">And, now the output will look like this.</p><figure id="2fee"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*ghs2bfMLywiVcn61"><figcaption></figcaption></figure><p id="4f50">Link to the repo page: <a href="https://github.com/dundee/gdu">https://github.com/dundee/gdu</a></p><h1 id="6c18">12. Byobu (Terminal Multiplexer)</h1><p id="eb0d">Byobu is simple to install, yet very powerful to use. The installation will be done like below. There is no external ppa required for ubuntu.</p><div id="0648"><pre><span class="hljs-variable">$ </span>sudo apt install byobu</pre></div><p id="f4f6">It needs to be added to list of available shells, using command which byobu | tee -a /etc/shells .</p><p id="6de8">In the terminal preferences, it is also need to set the “/usr/bin/byobu” as executable.</p><figure id="79bb"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*yQ3gh6LHdiljq6yt"><figcaption></figcaption></figure><p id="267d"><b>Link to shell functions:</b></p><div id="8ec3" class="link-block"> <a href="https://github.com/sarvsav/handy"> <div> <div> <h2>GitHub - sarvsav/handy: A handful set of shell commands</h2> <div><h3>You can't perform that action at this time. You signed in with another tab or window. You signed out in another tab or…</h3></div> <div><p>github.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*zzA0Ljn2WJiam7Si)"></div> </div> </div> </a> </div><h1 id="2259">13. lsd — next gen ls command</h1><p id="9dd0">It adds icon, colors, and in-built support of <code>tree</code> to your default <code>ls</code> command. It can be installed by downloading from <a href="https://github.com/lsd-rs/lsd/releases">HERE</a> and adding it to your <code>PATH</code> variable.</p><figure id="d172"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*DIltitsF3uAPynZCdQ4xsQ.png"><figcaption></figcaption></figure><figure id="67d2"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*ETMuOWrTRTnf2BOv67y_fQ.png"><figcaption></figcaption></figure><p id="2bcf">My default alias:</p><div id="a75f"><pre><span class="hljs-built_in">alias</span> <span class="hljs-built_in">ls</span>=<span class="hljs-string">"lsd -al"</span> <span class="hljs-built_in">alias</span> lt=<span class="hljs-string">"lsd --tree"</span></pre></div><h1 id="46cd">14. Zoxide</h1><p id="0d43">Remember your paths in terminal. The installation instructions can be found here: <a href="https://github.com/ajeetdsouza/zoxide#installation">https://github.com/ajeetdsouza/zoxide#installation</a></p><div id="043c"><pre>z foo <span class="hljs-comment"># cd into highest ranked directory matching foo</span> z foo bar <span class="hljs-comment"># cd into highest ranked directory matching foo and bar</span> z foo / <span class="hljs-comment"># cd into a subdirectory starting with foo</span>

z ~/foo <span class="hljs-comment"># z also works like a regular cd command</span> z foo/ <span class="hljs-comment"># cd into relative path</span> z .. <span class="hljs-comment"># cd one level up</span> z - <span class="hljs-comment"># cd into previous directory</span>

zi foo <span class="hljs-comment"># cd with interactive selection (using fzf)</span>

z foo<SPACE><TAB> <span class="hljs-comment"># show interactive completions (zoxide v0.8.0+, bash 4.4+/fish/zsh only)</span></pre></div><p id="e059">And, I alias it to <code>cd</code> command.</p><h1 id="0b63">15. RipGrep</h1><p id="cee4">Written in rust and while used fzf, it gives out of the box results. You can see the results in preview window with <code>fzf</code> and highlight text. Installation instructions can be found here: <a href="https://github.com/BurntSushi/ripgrep#installation">https://github.com/BurntSushi/ripgrep#installation</a></p><p id="e314">Add below code to your <code>.rc</code> file and then use the search command to search for a keyword. It will list all the files with the keyword with a preview and you can filter the files by entering the name.</p><div id="fa5e"><pre><span class="hljs-keyword">function</span> findme { rg --line-number --no-heading --color=always --smart-case <span class="hljs-string">"<span class="hljs-variable">$1</span>"</span> | fzf -d <span class="hljs-string">':'</span> -n 2.. --ansi --no-sort --preview-window <span class="hljs-string">'right:30%:+{2}'</span> -- │ preview <span class="hljs-string">'bat --style=numbers --color=always --highlight-line {2} {1}'</span> }

<span class="hljs-built_in">alias</span> search=findme</pre></div><figure id="c099"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*m1yIhtluTydQzjy4x7yKfQ.png"><figcaption></figcaption></figure><p id="1ace">Left box allows me to filter the files, and right box is showing the preview.</p><p id="dc57"><b>Shell Script to install above tools:</b> I have written a shell script to quickly setup your ubuntu, and can be found here. You have to run the <code>main.bash</code> script and it will setup most of the things for you. (Beta state)</p><div id="a6ca" class="link-block"> <a href="https://github.com/sarvsav/setup-ubuntu"> <div> <div> <h2>GitHub - sarvsav/setup-ubuntu: A list of tools that will install and bootstrap your ubuntu machine</h2> <div><h3>A list of tools that will install and bootstrap your ubuntu machine - GitHub - sarvsav/setup-ubuntu: A list of tools…</h3></div> <div><p>github.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*_E0XfYEmCHVCrKAj)"></div> </div> </div> </a> </div><p id="deed"><b>Bonus:</b></p><p id="c8d2">1. The shell theme used is <a href="https://github.com/carloscuesta/materialshell">materialshell</a>.</p><p id="1dee">2. autocomplete only for mac users. <a href="https://github.com/withfig/autocomplete">withfig/autocomplete: IDE-style autocomplete for your existing terminal & shell (github.com)</a></p><p id="7e00">3. A readme generator for your project <a href="https://github.com/kefranabg/readme-md-generator">kefranabg/readme-md-generator: 📄 CLI that generates beautiful README.md files (github.com)</a></p><p id="e8c4">Hope you find it useful. :)</p><p id="ae94">Shower your love by claps and shares ❤</p><p id="69e5">Clap guide in summary:</p><p id="afb7">1–2 Claps — An average article</p><p id="de0e">3–10 Claps — Very good article</p><p id="7da3">11–20 Claps — Very helpful and value addition</p><p id="35a8">21+ Claps — Supporting your efforts :)</p></article></body>

Top 10 things to make your linux terminal more productive

10 Tools to make terminal more productive

With the mindset of writing software, that integrates easily with others, we (software guys) have to spend more time on using terminal. Here are the top 10 things that you can add to your Linux terminal to make it more productive and fancy.

At the end of post, find link to github repo that contains shell functions to install these tools in a easy way.

1. Install the Zsh

The zsh shell is an alternative to bash shell and comes with lot of themes, and plugins). Installation of zsh is very easy and straight. With the package manager, you can install it by running below command:

$ sudo apt install zsh

Once installed, it’s recommended to set it as your default shell.

2. Install oh-my-zsh

oh-my-zsh is zsh framework, and it makes the shell more powerful. With oh-my-zsh, you can easily manage your shell configuration. To install oh-my-zsh, use below command:

$ sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

More details can be found here.

Bonus:

  1. There is a new shell (not stable version released) nushell and can be downloaded from here. Current version as of 29th May 2023, is v0.80.0.

2. Starship: The minimal, blazing-fast, and infinitely customizable prompt for any shell!

Download the FiraCode Nerd font from HERE.

And, install it for your shell using the guide from HERE.

This will give you the folder name, branch name, project language, and battery %age. The starship can be configured to do more powerful things also.

3. The fuzzyfinder (fzf)

Make your ctrl+r (backward search) more amazing, by installing fzf. It can be installed using below command.

$ sudo apt install fzf

Once installed, it will look like this:

Searching all the files, ending with .go extension. Dollar symbol represents end here. More details about the fuzzyfinder is present on the github page.

4. autojump

A cd command that learns — easily navigate directories from the command line. Installation can be done using below command. More details are available on their github.

$ sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

Bonus: (Credits: Hella Fast changing directory)

alias g="new_loc=\$(cat ~/.local/share/autojump/autojump.txt | sort -n | grep -Po '^[^\s]+\s+(\K.*)' | fzf +s -e) && cd \"\$new_loc\""

This requires both autojump and fzf to be installed. Autojump’s job here is to keep track of your most visited directories. It saves these entries at ~/.local/share/autojump/autojump.txt

5. jq and fx

JSON data download from mozilla network, and can be found here.

Most of our time, we spent on analyzing json output. These 2 tools, will make your life. You can easily install both of them using below commands:

fx

Save the data into the file named data.json and try to run the below command:

$ go install github.com/antonmedv/fx@latest
$ cat data.json | fx

On running the above command, it will open the json in interactive format. The reducers function can also be implemented with fx, and details can be found on documentation of the project.

./jq

is a command line json parser, and installation instructions are present on their homepage:

jq (stedolan.github.io). It filters to format the output. Installation can be done using the package manager.

$ sudo apt install jq

To get the output in list

A very nice tutorial on jq can be found on this link by Adam Gordon Bell.

6. Colorizing Cat or Bat

BAT (written in rust)

It can be downloaded from here: https://github.com/sharkdp/bat/releases and just add it to the path. On running below command:

bat sample.json

CCAT (written in go)

It is so boring to use the cat command, and difficulty to read the files on remote server. The ccat utility will highlight the syntax for you while reading the file.

From boring output:

To fancy output:

It can be installed using go and once installed can be set as an alias for cat command. Use the below command to download and for alias.

$ go install github.com/owenthereal/ccat

More details and information about the options can be found on the repo homepage.

Combining ccat with jq or fx , will make it more powerful. Add the below function in your .zshrc or .bashrc file.

function catme {
 filename=$(basename -- "$1")
 extension="${filename##*.}"
 filename="${filename%.*}"

 case "$extension" in
  "json") 
   ccat "$1" | jq -C
   ;;
  "md")
   glow "$1"
   ;;
  "csv")
    result=$(gum table < "$1")
    ;;
  *) 
   bat "$1"
   ;;
 esac
}

alias cat=catme

The above function can be extended to support multiple extensions.

Without ccat

With ccat

With alias and below function (It prints pretty with colors):

7. glow from charmbracelet

The above function can be extended to handle parsing of README files on terminal. The glow can be added as a file check to it. To install glow on your machine, run the below command:

go install github.com/charmbracelet/glow@latest

I am using a sample readme file to demonstrate the power of glow.

Without glow:

With glow:

8. gum — Improve your shell scripts

gum is mostly used to write better shell scripts, however I am using it for better reading the csv files in tabular format. It can be installed using below command:

go install github.com/charmbracelet/gum@latest

csv file without gum

Default output from bat

csv file with gum

Update the catme function in your .rc file to use gum .

9. carbon-cli

carbon-now is a very popular website to take screenshots of your code. Now, it can be done using command line too. Install it with below command.

$ npm i -g carbon-now-cli

And, the screenshots can be taken like this:

$ carbon-now filename.js

Result:

More information can be found on the project page.

10. diff-so-fancy

It feels so difficult to understand the diff between any two files. Not anymore, with usage of diff-so-fancy, reading diff becomes very easy. Installation is as simple as cloning this repo and then putting the diff-so-fancy script in to your $PATH. The lib/ directory will need to be kept relative to the core script.

Repo link: so-fancy/diff-so-fancy: Good-lookin’ diffs. Actually… nah… The best-lookin’ diffs. (github.com)

11. duf or gdu

duf

A fancy way of listing disk usage and free. It can be installed using below command.

$ go install github.com/muesli/duf@latest

gdu

du is a disk usage command, and very popular among linux administrator. However, with missing features like no updates on progress, it is difficult to use. To make the output for fancy, there is a tool written in go named gdu can be used. The installation is very simple, and can be done using below command.

$ go install github.com/dundee/gdu/v5/cmd/gdu@latest

And, now the output will look like this.

Link to the repo page: https://github.com/dundee/gdu

12. Byobu (Terminal Multiplexer)

Byobu is simple to install, yet very powerful to use. The installation will be done like below. There is no external ppa required for ubuntu.

$ sudo apt install byobu

It needs to be added to list of available shells, using command which byobu | tee -a /etc/shells .

In the terminal preferences, it is also need to set the “/usr/bin/byobu” as executable.

Link to shell functions:

13. lsd — next gen ls command

It adds icon, colors, and in-built support of tree to your default ls command. It can be installed by downloading from HERE and adding it to your PATH variable.

My default alias:

alias ls="lsd -al"
alias lt="lsd --tree"

14. Zoxide

Remember your paths in terminal. The installation instructions can be found here: https://github.com/ajeetdsouza/zoxide#installation

z foo              # cd into highest ranked directory matching foo
z foo bar          # cd into highest ranked directory matching foo and bar
z foo /            # cd into a subdirectory starting with foo

z ~/foo            # z also works like a regular cd command
z foo/             # cd into relative path
z ..               # cd one level up
z -                # cd into previous directory

zi foo             # cd with interactive selection (using fzf)

z foo<SPACE><TAB>  # show interactive completions (zoxide v0.8.0+, bash 4.4+/fish/zsh only)

And, I alias it to cd command.

15. RipGrep

Written in rust and while used fzf, it gives out of the box results. You can see the results in preview window with fzf and highlight text. Installation instructions can be found here: https://github.com/BurntSushi/ripgrep#installation

Add below code to your .rc file and then use the search command to search for a keyword. It will list all the files with the keyword with a preview and you can filter the files by entering the name.

function findme {
     rg --line-number --no-heading --color=always --smart-case "$1" | fzf -d ':' -n 2.. --ansi --no-sort --preview-window 'right:30%:+{2}' --       │ preview 'bat --style=numbers --color=always --highlight-line {2} {1}'
}
 
alias search=findme

Left box allows me to filter the files, and right box is showing the preview.

Shell Script to install above tools: I have written a shell script to quickly setup your ubuntu, and can be found here. You have to run the main.bash script and it will setup most of the things for you. (Beta state)

Bonus:

1. The shell theme used is materialshell.

2. autocomplete only for mac users. withfig/autocomplete: IDE-style autocomplete for your existing terminal & shell (github.com)

3. A readme generator for your project kefranabg/readme-md-generator: 📄 CLI that generates beautiful README.md files (github.com)

Hope you find it useful. :)

Shower your love by claps and shares ❤

Clap guide in summary:

1–2 Claps — An average article

3–10 Claps — Very good article

11–20 Claps — Very helpful and value addition

21+ Claps — Supporting your efforts :)

Linux
Bash
Terminal
Shell
Ubuntu
Recommended from ReadMedium