@@ -106,155 +106,22 @@ function recent-branches() {
106106 echo $output
107107}
108108
109- # Autocomplete function for c command
110- # function _c() {
111- # cur=${COMP_WORDS[COMP_CWORD]}
112- # branches=`git for-each-ref --sort=-committerdate refs/heads/ | head -n 10`
113-
114- # # By default bash breaks on "words", not lines. Set this magical garbage
115- # # so autocomplete works with line breaks, not one big string
116- # local IFS=$'\n'
117-
118- # output=''
119- # while read -r branch;
120- # do
121- # output+=`echo $branch | sed 's/.*refs\/heads\///'`
122- # local rawBranchName=`git show --quiet $(echo $branch | cut -d' ' -f1) --pretty=format:"%h <%an> %s (%cr)\'"`
123- # # If a commit message has backticks or dollar signs in it, bash will
124- # # try to interpolate it when outputting. Escape backtick and dollar
125- # # sign to prevent that
126- # local sanitizedbranchName=`echo $rawBranchName | sed 's/\([$\`]\)/\\\1/g'`
127- # output+="'"
128- # output+=$sanitizedBranchname
129- # output+="'"$'\n'
130- # done <<< "$branches"
131-
132- # # Why do I lowercase the output?
133- # response=''
134- # for branch in $output
135- # do
136- # lowerBranch=`echo $branch | tr '[:upper:]' '[:lower:]'`
137- # if [[ $branch =~ .*$cur.* ]]; then
138- # response+=$branch$'\n'
139- # fi
140- # done
141-
142- # COMPREPLY=( $( compgen -W "$response" -- $cur ) )
143- # }
144-
145- # function c() {
146- # local newBranch=""
147- # local inputted=""
148-
149- # if [[ -z "$1" ]]; then
150- # local branchOutput=`git for-each-ref --sort=-committerdate refs/heads/ | head -n 10`
151- # local IFS=$'\n'
152-
153- # # Bash syntax for declaring array
154- # declare -a branches
155-
156- # local counter=0
157- # local longestBranchLength=0
158-
159- # # When padding the output with printf, we need to take into account the
160- # # length of the branch name, plus any color codes we use, which aren't
161- # # printed, but are counted in printf's %-10s padding. We need to add in
162- # # the estimated string length of the color escape codes (including
163- # # color reset) to pad the branch name correctly
164- # local colorLength=4
165- # local numberOfColors=8
166-
167- # # Find the longest branch name for padding...
168- # while read -r branch;
169- # do
170- # local branchName=`echo "$branch" | sed 's/.*refs\/heads\///'`
171- # if [[ "${#branchName}" -gt "$longestBranchLength" ]]; then
172- # longestBranchLength=${#branchName}
173- # fi
174- # done <<< "$branchOutput"
175-
176- # # Calculate how many characters to pad including color code length...
177- # let local padLength="( longestBranchLength + 2 ) + ( colorLength * numberOfColors )"
178-
179- # # Show branches in a list with a counter
180- # while read -r branch;
181- # do
182- # counter=`expr $counter + 1`
183- # local branches=("${branches[@]}" "$branch")
184- # local branchName=`echo "$branch" | sed 's/.*refs\/heads\///'`
185- # local branchNamePrefix="$COLOR_PURPLE$counter. $COLOR_PINK $branchName"
186- # local resetColor="$counter. $branchName"
187- # # this interpolates to something like `printf %-100s` which is
188- # # syntax for padding in printf
189- # printf "%-${padLength}s" $branchNamePrefix
190- # printf '%s \n' `git show --quiet $branchName --pretty=format:"%C(Yellow)%h %Cred<%an>%Creset %s %C(cyan)(%cr)%Creset"`
191- # done <<< "$branchOutput"
192-
193- # # Prompt user for file. -n means no line break after echo
194- # echo -n "$COLOR_YELLOW?$COLOR_RESET "
195- # read branchNumber
196-
197- # let "branchNumber+=-1"
198-
199- # branchLength=${#branches[@]}
200-
201- # # lol runtime type checking
202- # if [[ "$branchNumber" =~ ^[0-9]+$ ]]; then
203-
204- # if [[ "$branchNumber" -ge "$branchLength" ]]; then
205- # if [[ $branchLength == "1" ]]; then
206- # echo "${COLOR_LIGHT_RED}Really?${COLOR_RESET}"
207- # elif [[ "$branchNumber" == "10" ]]; then
208- # echo "${COLOR_LIGHT_RED}This one doesn't go to eleven :(${COLOR_RESET}"
209- # else
210- # echo "${COLOR_LIGHT_RED}Please enter a number from 1 to ${branchLength}${COLOR_RESET}"
211- # fi
212- # return 1
213- # fi
214-
215- # newBranch=`echo "${branches[@]:$branchNumber:1}" | sed 's/.*refs\/heads\///' 2> /dev/null`
216-
217- # if [[ -z "$newBranch" ]]; then
218- # echo "${COLOR_LIGHT_RED}No git branch found named '${COLOR_CYAN}${newBranch}${COLOR_LIGHT_RED}?'${COLOR_RESET}"
219- # return 1
220- # fi
221- # else
222- # echo "${COLOR_LIGHT_RED}Please enter a numeric value.${COLOR_RESET}"
223- # return 1
224- # fi
225- # else
226- # inputted=1
227- # newBranch=`echo "$1" | cut -d' ' -f1`
228- # fi
229-
230- # if [[ -n "$1" ]]; then
231- # echo `git show --quiet "$newBranch" --pretty=format:"%C(Yellow)%h %Cred<%an>%Creset %s %C(cyan)(%cr)%Creset"`
232- # fi
233-
234- # if [[ $newBranch =~ ^pr ]]; then
235- # echo -e "\ngit fetch $newBranch && git checkout $newBranch"
236- # git fetch $newBranch && git checkout $newBranch
237- # else
238- # echo -e "\ngit checkout $newBranch"
239- # git checkout $newBranch
240- # fi
241-
242- # }
243-
244- # Wire up autocomplete
245- # complete -F _c c
246-
247- # Probably don't need this anymore, and could be a dangerous mis-type
248- # function rbd() {
249- # git fetch upstream && git rebase upstream/dev
250- # }
251-
252- # required for grunt ct
253- # export LANG=en_US.UTF-8
254- # export LC_ALL=
255-
256109function what-is-listening-on-port() {
257- lsof -n -i4TCP:$1 | grep LISTEN
110+ lsof -n -i4TCP:" $1 " | grep LISTEN
111+ }
112+
113+ function kport() {
114+ local procc
115+ procc=$( lsof -n -i4TCP:" $1 " | grep LISTEN)
116+
117+ if [[ -z $procc ]]; then
118+ echo " Nothing listening on port $1 "
119+ else
120+ local pid
121+ pid=$( echo " $procc " | awk ' {print $2}' )
122+ echo " kill -2 $pid "
123+ kill -2 " $pid "
124+ fi
258125}
259126
260127# Don't wait for job termination notification
0 commit comments