Skip to content

Instantly share code, notes, and snippets.

@takac
Created June 9, 2015 13:13
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 takac/bb1bc81129fecc672c02 to your computer and use it in GitHub Desktop.
Save takac/bb1bc81129fecc672c02 to your computer and use it in GitHub Desktop.
Useful shell functions
function agv()
{
command ag $@ | vim -c "setlocal buftype=nofile bufhidden=hide noswapfile" -c "let @/="'"'$@'"'" | set hls" -
}
# List files in git status using relative paths
function gip()
{
# Can provide a matcher against the porcelain tags, i.e. "M ", "UU", etc
# If not provided return all files listed in git status
if [[ "$1" == "" ]]; then
local TYPE=".."
else
local TYPE="$1"
fi
local TOP_DIR=$(git rev-parse --show-toplevel)
# resolve the current relativity to the git dir
local REL="$(python -c 'import os.path; print os.path.relpath("'"$TOP_DIR"'", os.path.abspath("."))')"
git status --porcelain | sed -ne "/^$TYPE/s/^$TYPE \+/$REL\//p" -e 's/\n/ /'
}
function gim()
{
vim $(gip)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment