I will admit it.  I am sometimes lazy.  And forgetful.  And despite my preference for working at the Linux command line rather than a GUI, I don't really like to type any more than I need to.  It is good to know these things about oneself.  It has also lead me to create and discover some tips and tricks to use in a Ubuntu bash command shell to help my productivity.  Keep in mind the hacks below all require edits to the user .bashrc file (~/.bashrc) and are known to work in Ubuntu 18.04 LTS.  If you aren't comfortable editing the .bashrc file then proceed with caution (and make a backup first!).  Here are a few of my favorites:

  • I mentioned I am lazy and don't like to type any more than I need to.  Setting up command aliases is a great way to minimize what you need to type, especially for commands that you need to run often.  Here are a few of my favorite aliases:
    • This alias only applies to Xilinx users and developers.  Print the Xilinx environment variables to remind me what version of tools my environment is set for.  This is especially handy if you have more than one version of Vivado, etc. installed at one time and often have to work in each of them simultaneously:
      alias pxil='printenv |grep XILINX; printenv |grep PETALINUX; printenv |grep VITIS'
      $ pxil

    • Search through the command history for a particular command.  I mentioned I was forgetful and lazy, and I often forget the exact syntax of a command that I know I have typed before.  I use this alias to help me re-run commands easily ($ !<command number>) or jog my memory for the syntax:
      alias hgrep='history |grep '
      $ hgrep <command name, or string in command>

    • Find out the status of the git repository I am working in.  Do I have any uncommitted changes?
      alias gstat='git status'
      $ gstat

    • What branch am I working on in my git repository?
      alias gbr='git branch'
      $ gbr

    • I often have more than one dev board connected to my PC, and forget which Linux ttyUSB device(s) they are connected to.  Depending on the dev board this command will reply with more than one ttyUSB device per dev board (some dev boards have more than one UART), so I still have to figure out the one I need, but at least this command helps me limit my choices:
      alias lsgusb='ls /dev |grep USB'
      $ lsgusb

    • This alias does the same as searching for attached ttyUSB devices, except for UARTs that are known to Linux as ttyACM devices:
      alias lsgacm='ls /dev |grep ACM'
      $ lsgacm

  • When working in a git repository I have been known to forget what branch I am working in, only to make a change to a source file that I shouldn't have.  This creates extra work to undo a commit or wastes work to have to stash any changes that can't be committed (because I am on the wrong branch).  Thanks to the community at stackoverflow.com there is a hack to the .bashrc file that adds the current git branch to the command line prompt.  This has saved me immeasurable grief from making changes in the wrong branch!  Be careful when making this edit and be sure to backup  your .bashrc file first!
    #https://stackoverflow.com/questions/15883416/adding-git-branch-on-the-bash-command-prompt
    parse_git_branch() {
        git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
    }
    if [ "$color_prompt" = yes ]; then
        PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\[\033[32m\]$(parse_git_branch)\[\033[00m\]$ '
    else
        PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(parse_git_branch)\$ '
    fi

  • This hack only applies to Xilinx users and developers.  Here is a hack to add the Xilinx environment variable settings setup scripts so they always run whenever you open a Ubuntu command shell.  Put this at the end of the .bashrc file and edit the path to match where your Xilinx tools are installed:
    #
    # Setup Xilinx environment
    #
    TOOLS_VER=2020.2
    source /path/to/Xilinx/Vitis/$TOOLS_VER/settings64.sh
    source /path/to/Xilinx/Vivado/$TOOLS_VER/settings64.sh
    source /path/to/Xilinx/PetaLinux/$TOOLS_VER/settings.sh

I hope you find these Ubuntu .bashrc hacks, tips, and tricks helpful.  I am interested to know what some of your favorite Ubuntu, Xilinx, and embedded Linux productivity hacks are.  What command aliases, git tricks, etc. make you more productive and you can't work without?  If you have any please leave them in the comments below!