@@ -96,10 +96,69 @@ until validation aliases like:
9696alias yamlcheck='python -c "import sys, yaml as y; y.safe_load(open(sys.argv[1]))"'
9797```
9898
99- Then Spencer told about customized prompts for git, filesystems or
100- tools, and about git config aliases.
99+ Then Spencer spoke about customized prompts for git, filesystems and
100+ tools, and about git config aliases, for example:
101101
102+ ```
103+ [alias]
104+ sgrep = "!f(){git submodule foreach \"git grep '$1' true \"
105+ | grep -B 1 \"$1\"}; f"
106+ ```
107+
108+ After that came functions. Some were general like:
109+
110+ ```
111+ # Get to the top of a git tree
112+ cdp (){
113+
114+ TEMP_PWD=`pwd`
115+ while ! [ -d .git ]; do
116+ cd ..
117+ done
118+ OLDPWD=$TEMP_PWD
119+
120+ }
121+ ```
122+
123+ Others were related to Gerrit or GitHub:
124+
125+ ```
126+ # Check out a Pull request from github
127+ function pr(){
128+ id=$1
129+ if [ -z $id ]; then
130+ echo "Need Pull request number as argument"
131+ return 1
132+ fi
133+ git fetch origin pull/${id}/head:pr_${id}
134+ git checkout pr_${id}
135+ }
136+ ```
137+
138+ In the end Spencer showed how to combine multiple small features to
139+ get something interesting. First vim can be started at a given line by
140+ giving the line in a +[ num] argument, for example ` vim +24 ` , then one
141+ can get the previous command typed on the command line using
142+ ` history | tail -n 2 | head -1 ` , and finally one can use ` git grep -n XXX `
143+ to get a grep result from Git with a line number.
144+
145+ These 3 small tricks can be used in the following big one:
146+
147+ ```
148+ # Have vim inspect command history
149+ vim (){
150+ last_command=$(history | tail -n 2 | head -n 1)
151+ if [[ $last_command =~ 'git grep' ]] && [[ "$*" =~ :[0-9]+:$ ]]; then
152+ line_number=$(echo $* | awk -F: '{print $(NF-1)}')
153+ /usr/bin/vim +${line_number} ${*%:${line_number}:}
154+ else
155+ /usr/bin/vim "$@"
156+ fi
157+ }
158+ ```
102159
160+ That makes vim open file "foo" at line "X" if one uses ` vim foo:X `
161+ just after having run ` git grep ` .
103162
104163* [ GSoC 2016] ( http://thread.gmane.org/gmane.comp.version-control.git/292308/ )
105164
0 commit comments