Colored terminal for windows linux subsystem

Colored terminal for windows linux subsystem

I share my terminal configuration that I use every day for my laptop. I always like to have ergonomic and colored informations with a command line interface. I was not satisfied with default linux tools (for this purpose) and customizable shell such as ZSH (regarding performances on Windows + proxy mainly).

Select a command line interface

Customized prompt

First I choose my command line interface. I realy like Hyper it’s very beautifull software,highly configurable in a simple json file, have plugins support and multiplatform.

The only thing that is missing on this interface is clearly a better startup tab management, especially on windows to start multiple tabs with Ubuntu subsystem, cmd, powershell in one clic.

Select a picto friendly font for your console output

Nerd Fonts is a project that patches developer targeted fonts with a high number of glyphs (icons). Specifically to add a high number of extra glyphs from popular ‘iconic fonts’

For my terminal, I choose DejaVuSansMono NF

- I simply installed it on windows with a right clic and "install".
- Then I update hyper to take this font as the default one.

.hyper.js

    fontFamily: '"DejaVuSansMono NF", monospace',

Configure prompt with git and picto in .bashrc

Next step was to improve prompt with clear and visual informations thanks to nerd font. A little bit of dirty scripting is needed here (perhaps this part could be improved for performances) to be able to retrieve git informations to prompt when you are on a repo folder.

# get current status of git repo
function parse_git_branch() {
        BRANCH=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
        if [ ! "${BRANCH}" == "" ]
        then                
				STAT=`parse_git_dirty`
                echo " [${BRANCH}${STAT}]"
        else
                echo ""
        fi
}

function parse_git_dirty {
	status=`git status 2>&1 | tee`
	dirty=`echo -n "${status}" 2> /dev/null | grep "modified:" &> /dev/null; echo "$?"`
	untracked=`echo -n "${status}" 2> /dev/null | grep "Untracked files" &> /dev/null; echo "$?"`
	ahead=`echo -n "${status}" 2> /dev/null | grep "Your branch is ahead of" &> /dev/null; echo "$?"`
	newfile=`echo -n "${status}" 2> /dev/null | grep "new file:" &> /dev/null; echo "$?"`
	renamed=`echo -n "${status}" 2> /dev/null | grep "renamed:" &> /dev/null; echo "$?"`
	deleted=`echo -n "${status}" 2> /dev/null | grep "deleted:" &> /dev/null; echo "$?"`
	bits=''
	if [ "${renamed}" == "0" ]; then
		bits=">${bits}"
	fi
	if [ "${ahead}" == "0" ]; then
		bits="*${bits}"
	fi
	if [ "${newfile}" == "0" ]; then
		bits="+${bits}"
	fi
	if [ "${untracked}" == "0" ]; then
		bits="?${bits}"
	fi
	if [ "${deleted}" == "0" ]; then
		bits="x${bits}"
	fi
	if [ "${dirty}" == "0" ]; then
		bits="!${bits}"
	fi
	if [ ! "${bits}" == "" ]; then
		echo " ${bits}"
	else
		echo ""
	fi
}

# Configure my prompt output using DejaVuSansMono NF font that include pictos I want 
export PS1=" \u\[\e[m\]\[\e[32m\]\W\[\e[m\]\[\e[33m\]\`parse_git_branch\`\[\e[m\]  "

and here is the result !

Customized prompt

You can check :

  • your user logged name
  • the name of your current repo
  • A visual branch status of your git repo.

Colored utilities

Next step is to have improvement regarding utilities that your are using every day. Here is some of them.

lsd

Colorizes the ls output with color and icons.

Customized prompt

bat

bat supports syntax highlighting for a large number of programming and markup languages.

Customized prompt

fzf

It’s an interactive Unix filter for command-line that can be used with any list; files, command history, processes, hostnames, bookmarks, git commits, etc.

Customized prompt

if you want to upgrate your ctrl+r interface for command line history search

add to your .bashrc

[ -f ~/.fzf.bash ] && source ~/.fzf.bash

fd

fd is a simple, fast and user-friendly alternative to find.

tldr

A collection of simplified and community-driven man pages

Customized prompt

diff-so-fancy

diff-so-fancy strives to make your diffs human readable instead of machine readable. This helps improve code quality and helps you spot defects faster.

NB: Remember to add git-so-fancy to ther path vartiable on .bashrc file

export PATH=$PATH:/home/ibrahim/.prettyping:/home/ibrahim/.diff-so-fancy

prettyping

prettyping is a wrapper around the standard ping tool with the objective of making the output prettier, more colorful, more compact, and easier to read.

Customized prompt

htop

This is htop, an interactive process viewer for Unix systems. It is a text-mode application (for console or X terminals) and requires ncurses.

Customized prompt

w3m

w3m is a text-based web browser as well as a pager like more' or less’.

http

HTTPie—aitch-tee-tee-pie—is a command line HTTP client with an intuitive UI, JSON support, syntax highlighting, wget-like downloads, plugins, and more.

Customized prompt

Make some usefull aliases

.bash_aliases

alias ping='prettyping'
alias ls='lsd -la'
alias cat='bat'
alias preview="fzf --preview 'bat --color \"always\" {}'"
alias top="sudo htop"
alias find="fd"
alias man="tldr"
alias diff="diff-so-fancy"
alias browser="w3m"
alias wget="http -df"

alias powershell="/mnt/c/Program\ Files/PowerShell/7-preview/pwsh.exe -WorkingDirectory C:/Users/<USER>"
alias winps="tasklist.exe /svc"
alias winkillall="taskkill.exe /F /IM"
alias vscode="/mnt/c/Users/<USER>/AppData/Local/Programs/Microsoft\ VS\ Code/Code.exe"

That’s all for today !