Skip to content

Instantly share code, notes, and snippets.

@davidhq
Last active September 11, 2015 22:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidhq/f37ac87bc77f27c5027e to your computer and use it in GitHub Desktop.
Save davidhq/f37ac87bc77f27c5027e to your computer and use it in GitHub Desktop.
# Example:
#
# $ find . | grep core_ext
# ./config/initializers/core_ext.rb
# ./spec/lib/core_ext_spec.rb
#
# $ grab 2
# ./spec/lib/core_ext_spec.rb ===> (also copied on clipboard)
#
# Without arguments the default is to grab the first line
grab() {
local num=1
if [ -n "$1" ]; then
num=$1
fi
local line=`$(history | tail -2 | head -1 | cut -d" " -f4-) | sed "${num}q;d"`
echo $line
echo $line | tr -d "\n" | pbcopy
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment