Archive for the ‘bash’ Category


August 1, 2017 Leave a comment

Well this was more like an irritant. I have a portforwarding script that I manually start. I just got tired of doing that and moved it to an upstart task.

Added the following job for upstart to handle.

$ less /etc/init/portforward.conf
description     "Portforward 3141 to devpi server"

author      "Vagrant"

start on runlevel [2345]
stop on runlevel [!2345]

    cd /home/vagrant

    export SSHPASS="vagrant"
    sshpass -e ssh -nNL 3141: -o ConnectTimeout=10 -o LogLevel=Error -o StrictHostKeyChecking=no vagrant@
end script
$ # Check the syntax
$ init-checkconf /etc/init/portforward.conf
$ # Start the job
$ sudo service portforward start


Categories: bash Tags: ,

A Powerline style prompt for your shell

July 23, 2017 Leave a comment

For a hassle free powerline like shell. Works with bash and zsh.

* Shows some important details about the git/svn/hg/fossil branch (see below)
* Changes color if the last command exited with a failure code
* If you’re too deep into a directory tree, shortens the displayed path with an ellipsis
* Shows the current Python virtualenv environment
* It’s easy to customize and extend. See below for details.

Categories: bash, zsh Tags:


July 23, 2017 Leave a comment

Git status with powerline


1. pip install –user powerline-gitstatus

Follow the instructions in on site
2. Add custom highlight groups.

vim .local/lib/python2.7/site-packages/powerline/config_files/colorschemes/default.json


  "groups": {
    "gitstatus":                 { "fg": "gray8",           "bg": "gray2", "attrs": [] },
    "gitstatus_branch":          { "fg": "gray8",           "bg": "gray2", "attrs": [] },
    "gitstatus_branch_clean":    { "fg": "green",           "bg": "gray2", "attrs": [] },
    "gitstatus_branch_dirty":    { "fg": "gray8",           "bg": "gray2", "attrs": [] },
    "gitstatus_branch_detached": { "fg": "mediumpurple",    "bg": "gray2", "attrs": [] },
    "gitstatus_tag":             { "fg": "darkcyan",        "bg": "gray2", "attrs": [] },
    "gitstatus_behind":          { "fg": "gray10",          "bg": "gray2", "attrs": [] },
    "gitstatus_ahead":           { "fg": "gray10",          "bg": "gray2", "attrs": [] },
    "gitstatus_staged":          { "fg": "green",           "bg": "gray2", "attrs": [] },
    "gitstatus_unmerged":        { "fg": "brightred",       "bg": "gray2", "attrs": [] },
    "gitstatus_changed":         { "fg": "mediumorange",    "bg": "gray2", "attrs": [] },
    "gitstatus_untracked":       { "fg": "brightestorange", "bg": "gray2", "attrs": [] },
    "gitstatus_stashed":         { "fg": "darkblue",        "bg": "gray2", "attrs": [] },
    "gitstatus:divider":         { "fg": "gray8",           "bg": "gray2", "attrs": [] }

3. Activate the Gitstatus segment.

vim .local/lib/python2.7/site-packages/powerline/config_files/colorschemes/default.json


    "function": "powerline_gitstatus.gitstatus",
    "priority": 40

4. Show most recent tag reachable in the current branch.

vim .local/lib/python2.7/site-packages/powerline/config_files/themes/shell/__main__.json


"gitstatus": {
    "args": {
        "show_tag": true

These are json files. Be careful with syntax. If editing existing files, remember to add the necessary commas where needed.



July 23, 2017 Leave a comment

Installing powerline-status

1. pip install –user powerline-status
2. Add the following to .bashrc

if [ -d "$HOME/.local/bin" ]; then

export POWERLINE_COMMAND=powerline
powerline-daemon -q

. ${REPOSITORY_ROOT}/powerline/bindings/bash/

3. Source .bashrc. It may give some errors. Open up a new terminal and see if the changes have taken effect.

$ source .bashrc
bash: /home/rodnee/.local/lib/python2.7/site-packages/powerline/bindings/bash/../../../scripts/powerline-config: No such file or directory
bash: /home/rodnee/.local/lib/python2.7/site-packages/powerline/bindings/bash/../../../scripts/powerline-config: No such file or directory


I could not get it to work with zsh. Opted for instead.

Categories: bash Tags: ,

encryption failed: Unusable public key

April 4, 2017 Leave a comment

Problem: gpg2 gives you an “Unusable public key” error when trying to encrypt a file.

gpg2 --output encrypted_file.gpg  --recipient <mykey> --recipient <other-guy's-key>  --encrypt file-being-encrypted.txt
gpg: <other-guy's-key>: skipped: Unusable public key
gpg: file-being-encrypted.txt: encryption failed: Unusable public key

In this case, the key had expired and needed to be refreshed.

A simple “gpg2 –refresh-keys” failed to run. So I opted to delete the key and try pull it down again.

gpg2 --keyserver hkp:// --recv-keys <other-guy's-key>
gpg: requesting key <other-guy's-key> from hkp server
gpgkeys: key <other-guy's-key> can't be retrieved
gpg: no valid OpenPGP data found.
gpg: Total number processed: 0
gpg: keyserver communications error: keyserver helper general error
gpg: keyserver communications error: Invalid public key algorithm
gpg: keyserver receive failed: Invalid public key algorithm

But when I tried again using an IP

gpg2 --keyserver  --recv-keys <other-guy's-key>
gpg: requesting key <other-guy's-key>8 from hkp server
gpg: key KEYID123: public key "Julius Ceasar <>" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)

Turns out that I need to update my gpg
For mac

$ brew upgrade gpg2

And now gpg2 works as expected without any issues.


Categories: bash Tags:

Ctrl + Left or Right arrow

November 17, 2016 Leave a comment

A colleague introduced me to using “Option + Left” shortcut on OSX. I’d like to set this up on my debian box.

Option/Alt + Left or Right

This shortcut allows you to move the cursor between separate words in a command line. Use Option and the left arrow to move back and use Option with the right arrow to move forward down the line.

I’ll be using “Ctl + Left” to move back and “Ctl + Right” to move forward between separate words.

For bash:
Add the following to .inputrc

"\e[1;5D": backward-word
"\e[1;5C": forward-word

For zsh:
Add this to .zshrc

bindkey '^[[1;5C' forward-word
bindkey '^[[1;5D' backward-word

To find out what is being sent by the keyboard. Type Ctrl + C to quit.

$ cat -v    
# When pressing Ctrl + Left Arrow                           

# When pressing Ctrl + Right Arrow

Source: (Look at the “How can I see what my keyboard sends?” section)

Categories: bash, Interesting, zsh Tags:

Change key mapping from caps lock to control key

October 29, 2016 Leave a comment

I needed to remap my caps lock key to be ctrl for tmux key bindings. Now I can use capslock + a instead of ctrl + a.

Added the following to .bashrc

$ /usr/bin/setxkbmap -option "ctrl:nocaps"


Categories: bash Tags: ,