Skip to content

Instantly share code, notes, and snippets.

@lsilvs
Last active May 3, 2017 14:15
Show Gist options
  • Save lsilvs/bd0d43dac862b85fbaa11a56f7ebae58 to your computer and use it in GitHub Desktop.
Save lsilvs/bd0d43dac862b85fbaa11a56f7ebae58 to your computer and use it in GitHub Desktop.
Git hook to keep track of opened files for each branch
#!/bin/sh
#
# This Git Hook uses OpenedFilesList Sublime plugin to
# keep track of your files used on each branch and
# open them automatically for you
#
# To enable this hook, save it to ".git/hooks/"
# and run "chmod ug+x .git/hooks/post-checkout".
if [ $3 == 1 ]; then
exec < /dev/tty
read -p "[post-checkout hook] Save workspace? (Y/n) " yn
if [ "$yn" = "" ]; then
yn='Y'
fi
if [ "$yn" = "Y" ]; then
toplevel_path=$(git rev-parse --show-toplevel)
branch_files_path="$toplevel_path/.git/branch_files"
$(mkdir -p $branch_files_path)
prev=$(git rev-parse --abbrev-ref @{-1})
curr=$(git rev-parse --abbrev-ref HEAD)
$(sublime --command opened_files_list)
if [ -f /tmp/subl_opened_files ]; then
$(mv /tmp/subl_opened_files $branch_files_path/$prev)
fi
if [ -f $branch_files_path/$curr ]; then
exec cat $branch_files_path/$curr |
while read line; do
sublime $line;
done
fi
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment