Script for 'Haxorz Day' at Selleo
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Git, shell & Vim tips & tricks

Script for Haxorz Day at Selleo.


Ignoring User Files

.gitignore is good for ignoring files shared among (almost) all developers. It cannot, however, filter out temporary, work–in–progress, or ‘private’ files.

.git/info/exclude is for that purpose.

Before git repo is initiated.

➜  haxorz_10.15  ls
asciinema_screencasts notes

Initiating git repo.

➜  haxorz_10.15 git:(master) ✗ git s
?? asciinema_screencasts/
?? notes/

I don’t want to push notes/ and other ‘WIP’ files.

➜  haxorz_10.15 git:(master) ✗ echo 'notes/' >> .git/info/exclude
➜  haxorz_10.15 git:(master) ✗ git s
?? asciinema_screencasts/

Now asciinema_screencasts can be pushed.

Opening previous revision(s) of a file

If you use Vim, consider using Extradite commit browser. For ‘vanilla’ Git, use this:

git show head~1:app/assets/javascripts/file.js

Modify ~1 to get previous revisions. You don’t have to start from head. Any valid Git hash like e051eff~5 can be used.

You can even checkout that file:

git checkout e051eff~1 app/assets/javascripts/file.js

Opening Github pull request with hub

hub pull-request and you don’t have to open Github page.

See git pull-request documentation for more info.

shell / zsh

Repeating last arguments in shell

You don’t have to do ‘copy–pasta’ to use last command arguments in another command.

asciinema_screencasts can be used in another command.

➜  haxorz_10.15 git:(master) ✗ ls asciinema_screencasts
# press `ALT-.` after `ls`
ls asciinema_screencasts

On OS X you may need ALT key to be configured to act as +Esc in options of your terminal emulator.

bindkey to list keyboard shortcuts in zsh

Use bindkey to list key bindings instead of googling how to ‘move forward one word’ (ALT-F if you’re wondering)

Rails / Pry

show-doc as an API viewer

? alias can be used instead.

[1] pry(main)> show-method Array#map

From: array.c (C Method):
Owner: Array
Visibility: public
Number of lines: 13

static VALUE
rb_ary_collect(VALUE ary)
    long i;
    VALUE collect;

    RETURN_SIZED_ENUMERATOR(ary, 0, 0, ary_enum_length);
    collect = rb_ary_new2(RARRAY_LEN(ary));
    for (i = 0; i < RARRAY_LEN(ary); i++) {
	rb_ary_push(collect, rb_yield(RARRAY_AREF(ary, i)));
    return collect;

show-doc is not limited to ruby / rails core methods. You can use show-method Dog#bark as well.

show-method to display any method

$ alias can be used instead.

➜  examples git:(master) ✗ ruby -r pry pig.rb
[1] pry(main)> $ Pig#eat

From: pig.rb @ line 8:
Owner: Pig
Visibility: public
Number of lines: 3

def eat
  "Om nom nom"

Pig examples taken from pry documentation ;)

Debugging with Pry

➜  examples git:(master) ✗ ruby -r pry pig.rb
[1] pry(main)> $ Pig#say_hello

def say_hello

‘dog–like’ pig? Let’s fix that!

[2] pry(main)> edit Pig#say_hello

def say_hello

Use -t to temporary changes (kept in memory)

 edit -t Pig#say_hello

Better code examples with asciinema

Forget screen recording apps and blurry video. Enjoy a lightweight, purely text based approach to terminal recording.

Visit asciinema website for more info.


asciicast was recorded with:

asciinema play -w=2 06_hx_debugging_with_pry.json

Example taken from Rubyists, It’s Time to PRY Yourself Off IRB! article on sitepoint.

formd to level–up your markdown links formatting

formd—A Markdown formatting tool

Markdown has two formats for links:

  • Inline
  • Referenced

Inline: good when you’re creating content. Bad for formatting (80 column–length) and reading.

The quick brown [fox]( jumped over…

Referenced: good for reading / reviewing text and formatting–friendly.

the lazy [dog](1)

With formd you can easily switch between the two.

From my .vimrc

au FileType markdown,text nmap <leader>fr :call Formd("-r")<CR>
au FileType markdown,text nmap <leader>fi :call Formd("-i")<CR>
au FileType markdown,text nmap <leader>ft :call Formd("-f")<CR>