Monday, January 26, 2015

Dropbox setup for shell scripts

There are quite a few shell scripts that that I have to have for my bash environment. For the last few years, I've backed these up to Dropbox and used symbolic links to insert them into the system.

Within Dropbox itself, I have a Scripts directory that I keep all my scripting files in. Most of these are dotfiles and in order to display them properly in Finder and other utilities, I prefix the word "dot" to the beginning and use CamelCase for readability. For example, my .profile is named dotProfile in the Scripts directory.

Here's a brief rundown of the files that I normally use:

.profile -> dotProfile

This mostly contains the aliases that I've accumulated over the years and a few shell settings.

alias ls='ls -G'
This basically shows document colors in the ls output. I could also set the CLICOLOR and LSCOLORS environment variables, but this is usually easier for me.

export HISTSIZE=10000
export HISTCONTROL=ignoredups:erasedups
shopt -s histappend
These three commands control the bash history. The HISTSIZE setting allows for a maximum of 10,000 lines to be saved in bash history. 

The HISTCONTROL setting removes duplicate lines from the history. I have a tendency to do ls a lot and it keeps my history from getting cluttered with multiple lines of the same thing. There's some interesting info on this setting in this StackExchange question.

The histappend setting has to do with the way bash handles multiple simultaneous sessions. Normally, the history is written at the end of each session and the file is overwritten. This setting appends new history lines at the end of the file instead.

.bash_history -> dotBash_history

If I'm going to all the trouble of making sure my bash history is the way I want it, I might as well back it up in Dropbox and have it available for parsing outside of a bash prompt.

.ssh -> dotSsh

This one is actually a directory and contains all my SSH settings. It's most important for having my authorized keys and known hosts available again whenever I have to reinstall or upgrade my OS. There are some security concerns that you need to take into consideration when saving information like this, but it's probably too long to go into on this post. I'll probably write it up someday.

.vimrc -> dotVimrc

Obviously vi/vim is my editor of choice. I've been using it for years, and have the options setup the way I like. I basically set the following:
  • syntax on
    • Turn on syntax highlighting. Works with most major programming languages, but I mostly use it for bash and Perl.
  • set showmode
    • Show the current mode on the last line
  • set number
    • Show line numbers
  • set ruler
    • Show the ruler, which is basically line and character position separated by a comma
  • set autoindent
    • Use smart autoindenting. Useful for keeping codeblocks in order.
  • set nocompatible
    • Reduce compatibility with vi in order to use more advanced features of vim.