This section will talk about how to update the Terminal’s look and feel, as well as how to edit files in Ubuntu through it’s command line editor nano.
Typically you will always be working in the Windows FS, but for this task we need to edit a file that lives on the Ubuntu FS. This means that we need to use nano to update the file, since Windows cannot update the Ubuntu file without causing errors.
At the end, this will add some color to your command line, and your command line will be formatted like this:
WorkingDirectory[GitBranch GitStatus]$
IE: about_me[monday-lab x!+]$
In order to change how your terminal looks, we need to add some code to a file that lives in your Ubuntu user’s root directory.
ls -a
. You should see a .profile file there. If not, then type sudo touch .profile
.sudo nano .profile
. This will open the file in the command line editor Nano.# get current branch in 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
}
# get current status of git repo
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
}
# PS1 is what actually defines what you command line prompt looks like.
export PS1="\[\e[m\]\[\e[36m\]\W\[\e[m\]\[\e[33m\]\`parse_git_branch\`\\$ "
# Everything above this point is used to change how your terminal looks. If you ever want to update your terminals look, change things above here.
# Nothing below here will change how your terminal looks, rather, it will change some things about how it works.
# This allows you to open html files in Chrome more easily by typing "chrome filename".
alias chrome="/mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe"
# This allows you to switch between the Ubuntu root and your Windows Root.
# wr evaluates to the absolute path to your Windows user's root.
export wr=~/../../mnt/c/Users/<Windows Username>/
# This gives us a quick way of moving directly to the Windows root
alias cdwr='cd "$wr"'
# This brings you to your Windows Working directory immediatly when you open a new terminal.
cdwr
/Users/
. IE: /Users/MichaelLeonTreat/
.4a. If your path has a space, you can use an backslash escape character to include the space. IE: /Users/Michael\ Treat/
.
ctrl + x
at the same time to quit. It will ask if you want to save changes. Hit y
and the editor will save your changes. It will then ask what to name the file. Just hit enter to keep the same name.And you’re done!
wr
and sets up the cdwr
alias. What this does is adds a unique variable and a command to your terminal.If you want to use a relative path, but don’t want to go all the way up to the Ubuntu FS and then work down to the Windows FS, you can use the $wr
variable as a shortcut to the Windows root instead. IE:
cd $wr/about_me/scripts
. Instead of:
cd ~/../../mnt/c/Users/MTreat/Development/about_me/scripts
This also works with tab completion as well, which is awesome.
Now when you type cdwr
it will bring you to the root of your Windows User! This makes navigating between the two file systems super easy.
cd ~
.cdwr
with NO space!If you decide to add a directory to your Windows User’s root to hold all of your work, IE: /Users/MichaelLeonTreat/Development
, you can come back to this file and update the export wr
line so that it moves directly into that directory. Just add the name of the directory to the end of the path after your username.
In case you ever need it, the Ubuntu FS lives on your Windows FS on the path that looks very similar to this:
C:\Users\<user>\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs
Once that’s done we can install a quick awesome command called tree
. What tree
does is displays all of your directories and files in a nicely formatted tree so you can easily see your current file structure!
Type sudo apt install tree
. Once that’s done, you can type tree
to see the tree view of the directory that you’re currently in! You may have to close and restart your terminal before it will work.
Before we can dive in and start coding, we should add in some software that will help us streamline the entire process. This next section will explain how to install 3 very common pieces of software, and will also cover the different situations you may encounter while using the two File Systems.