Archive

Archive for the ‘bash’ Category

upstart

August 1, 2017 Leave a comment

Problem:
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.

Solution:
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]

script
    cd /home/vagrant

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

Source:
https://www.digitalocean.com/community/tutorials/the-upstart-event-system-what-it-is-and-how-to-use-it

Advertisements
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.

https://github.com/banga/powerline-shell

Categories: bash, zsh Tags:

powerline-gitstatus

July 23, 2017 Leave a comment

Problem:
Git status with powerline

Solution:
https://github.com/jaspernbrouwer/powerline-gitstatus

1. pip install –user powerline-gitstatus

Follow the instructions in on site https://github.com/jaspernbrouwer/powerline-gitstatus
2. Add custom highlight groups.

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

Example

{
  "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

Example

{
    "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

Example

"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.

Source:
https://github.com/jaspernbrouwer/powerline-gitstatus

powerline-status

July 23, 2017 Leave a comment

Problem:
Installing powerline-status

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

if [ -d "$HOME/.local/bin" ]; then
    PATH="$HOME/.local/bin:$PATH"
fi

export POWERLINE_COMMAND=powerline
powerline-daemon -q

POWERLINE_BASH_CONTINUATION=1
POWERLINE_BASH_SELECT=1
REPOSITORY_ROOT=/home/rodnee/.local/lib/python2.7/site-packages
. ${REPOSITORY_ROOT}/powerline/bindings/bash/powerline.sh

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

Source:
http://powerline.readthedocs.io/en/master/index.html
https://github.com/powerline/powerline/issues/850

Note:
I could not get it to work with zsh. Opted for https://pseudoscripter.wordpress.com/2017/07/23/a-powerline-style-prompt-for-your-shell/ 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

Solution:
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://keys.gnupg.net --recv-keys <other-guy's-key>
gpg: requesting key <other-guy's-key> from hkp server keys.gnupg.net
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 140.211.169.202  --recv-keys <other-guy's-key>
gpg: requesting key <other-guy's-key>8 from hkp server 140.211.169.202
gpg: key KEYID123: public key "Julius Ceasar <julius.ceasar@example.com>" 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.

Source
https://github.com/rvm/rvm/issues/3544

Categories: bash Tags:

Ctrl + Left or Right arrow

November 17, 2016 Leave a comment

Problem:
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.

Solution:
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

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

$ cat -v    
# When pressing Ctrl + Left Arrow                           
^[[1;5D

# When pressing Ctrl + Right Arrow
^[[1;5C

Source:
http://superuser.com/questions/357355/how-can-i-get-controlleft-arrow-to-go-back-one-word-in-iterm2
http://invisible-island.net/ncurses/ncurses.faq.html#modified_keys (Look at the “How can I see what my keyboard sends?” section)

http://www.techrepublic.com/article/20-terminal-shortcuts-developers-need-to-know/

Categories: bash, Interesting, zsh Tags:

Change key mapping from caps lock to control key

October 29, 2016 Leave a comment

Problem:
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.

Solution:
Added the following to .bashrc

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

Source:
http://serverfault.com/questions/10437/how-do-you-swap-the-caps-lock-to-control-in-xfce#10537

Categories: bash Tags: ,