Archives For bash

If you forget to edit a file as a superuser like sudo vim file and you don’t want to leave your existing vim session, you can use the following snippet.

:w !sudo tee % > /dev/null

Remove All .pyc Files

August 16, 2013 — Leave a comment

Found a cool bash command to remove all the .pyc files from a project folder.

find . -name '*.pyc' -delete

I turned it into a bash alias in my ~/.bash_profile.

alias pyclean="find . -name '*.pyc' -delete"

The Command-T plug-in provides an extremely fast, intuitive mechanism for
opening files and buffers with a minimal number of keystrokes. It’s named
“Command-T” because it is inspired by the “Go to File” window bound to
Command-T in TextMate.

I was trying to install Command-T into VIM with the Pathogen plugin. I kept getting

checking for ruby.h... *** extconf.rb failed 
***Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

I realized my rvm environment was choosing the incorrect gcc and developer tools. I used the system ruby and was able to run everything without a hitch.

rvm use system    
cd ruby/command-t
ruby extconf.rb
make
sudo make install

Bash Shortcuts

July 9, 2013 — Leave a comment
  • Ctrl + A: Go to the beginning of the line you are currently typing on
  • Ctrl + E: Go to the end of the line you are currently typing on
  • Ctrl + F: Forward one character.
  • Ctrl + B: Backward one character.
  • Meta + F: Move cursor forward one word on the current line
  • Meta + B: Move cursor backward one word on the current line
  • Ctrl + P: Previous command entered in history
  • Ctrl + N : Next command entered in history
  • Ctrl + L: Clears the screen, similar to the clear command
  • Ctrl + U : Clears the line before the cursor position. If you are at the end of the line, clears the entire line.
  • Ctrl + H : Same as backspace
  • Ctrl + R: Lets you search through previously used commands
  • Ctrl + C : Kill whatever you are running
  • Ctrl + D: Exit the current shell
  • Ctrl + Z: Puts whatever you are running into a suspended background process. fg restores it.
  • Ctrl + W : Delete the word before the cursor
  • Ctrl + K: Kill the line after the cursor
  • Ctrl + Y : Yank from the kill ring
  • Ctrl + _: Undo the last bash action (e.g. a yank or kill)
  • Ctrl + T: Swap the last two characters before the cursor
  • Meta + T: Swap the last two words before the cursor
  • Tab: Auto-complete files and folder names

If you are familiar with Ubuntu, you’ll know that it has a tree command. You can install it into OSX, if you have Homebrew.

brew install tree

Afterwords, try

tree -C