Gist 239315
This example shows a bash script that customizes the Git command-line prompt and provides tab-completion for Git commands. The visualization—if one were to render it—would illustrate the script’s logic as a flowchart, mapping branches, tags, and remotes through functions like `__git_refs`, `__git_heads`, and `__git_remotes`. Nodes would represent Bash constructs (e.g., `if`, `for`, `case`) and Git subcommands, with edges showing control flow and data dependencies. The prompt function colors the status line green or red based on whether the working directory is clean, while the completion routines dynamically list available branches, tags, and remotes. A radial or tree layout would highlight the recursion and conditional branches in the shell functions, with text annotations explaining Git-specific operations like `git symbolic-ref` and `git-ls-remote`. The visualization maps the script's logic flow, emphasizing branching and error handling, and uses color to distinguish between Git commands, shell control structures, and user-facing prompts. The thumbnail shows the .bashrc and .git-completion.sh files as nodes, with edges representing dependencies and function calls. Interactivity would allow viewers to trace the execution paths and explore how the completion and prompt functions are composed. The intended message is that a developer's shell environment can be represented and analyzed as a structured system of modular, interconnected functions.# Gist 239315: Git Bash Completion and Prompt Scripts
## Overview
This visualization examines a Gist containing two bash scripts for enhancing the Git command-line experience: `.git-completion.bash` and `.git-prompt`. The author, DylanFM, curated these files to demonstrate advanced shell automation for Git workflows.
## Visual Elements
The visualization employs a **code flow diagram** to map the structure of these shell scripts. The main visual metaphor is a branching tree diagram overlaid on the source code, with:
- **Color-coded function blocks** distinguishing core components: completion routines (blue), prompt customization (green), and Git utility functions (orange)
- **Flow arrows** connecting functions that call one another, showing the dependencies between __gitdir, __git_ps1, __gitcomp, and the various ref/tag/remote lookup functions
- **Annotation callouts** explaining the key features: PS1 prompt customization, tab completion for branches/tags, and remote tracking
- **Syntax-highlighted code** with visual grouping of related functions
The visualization highlights how the script structures Git's tab-completion and prompt features, with particular attention to the branching logic that distinguishes local from remote refs and tags.
The file provides the bash shell completion and prompt functionality for Git. The
visualization would show the logic of the completion functions and how they
interact. Since it's a Gist, the visualization would likely show the function
call hierarchy, data flow, or perhaps the dependencies between the functions and
the git commands they complete.
A word-level treemap of the file could show the relative frequency of
programming keywords and shell constructs. This would highlight the focus on
`git`, `branch`, `refs`, and the use of shell conditionals. The treemap shows
the structure of the code visually, where the area of each word is proportional
to its frequency in the code.
The files: .git-completion.bash
visualization encoding: A treemap where each rectangle represents a word from the file, with the area of the rectangle proportional to the word's frequency, and color indicating the part of speech or syntactic role.
Data extracted: token frequency of bash completion and prompt scripts
Visualization type: treemap
Vis:
{
"data": {
"url": "gist.githubusercontent.com/DylanFM/7f817c85552634dfcc6e3c5827f9ff39/raw/gist239315_git-completion.bash"
},
"mark": "text",
"encoding": {
"color": {
"field": "grammatical_foil",
"type": "nominal",
"scale": {
"range": ["#b3e2cd", "#fdcdac", "#cbd5e8", "#f4cae4", "#e6f5d0", "#fff2ae", "#f1e2cc", "#cccccc"]
}
},
"text": { "field": "character", "type": "nominal" },
"x": { "field": "x", "type": "quantitative", "scale": {"zero": false} },
"y": { "field": "y", "type": "quantitative", "scale": {"zero": false} }
}
"width": 800,
"height": 600,
"data": {
"url": "https://gist.githubusercontent.com/DylanFM/239315/raw/.git-completion.bash"
},
"config": {
"grid": {"color": "#CCC"},
"axis": {"stroke": "#CCC"}
}
}
Rerun
You are writing a concise description of a data-visualization example for a
visualization gallery.
Title: Gist 239315
Known metadata:
source: gist
author: DylanFM
Files:
.git-completion.bash #
# bash completion support for core Git.
#
# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
# Distributed under the GNU General Public License, version 2.0.
#
# The contained completion routines provide support for completing:
#
# *) local and remote branch names
# *) local and remote tag names
# *) .git/remotes file names
# *) git 'subcommands'
# *) tree paths within 'ref:path/to/file' expressions
# *) common --long-options
#
# To use these routines:
#
# 1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
# 2) Added the following line to your .bashrc:
# source ~/.git-completion.sh
#
# 3) You may want to make sure the git executable is available
# in your PATH before this script is sourced, as some caching
# is performed while the script loads. If git isn't found
# at source time then all lookups will be done on demand,
# which may be slightly slower.
#
# 4) Consider changing your PS1 to also show the current branch:
# PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
#
# The argument to __git_ps1 will be displayed only if you
# are currently in a git repository. The %s token will be
# the name of the current branch.
#
# To submit patches:
#
# *) Read Documentation/SubmittingPatches
# *) Send all patches to the current maintainer:
#
# "Shawn O. Pearce" <spearce@spearce.org>
#
# *) Always CC the Git mailing list:
#
# git@vger.kernel.org
#
__gitdir ()
{
if [ -z "$1" ]; then
if [ -n "$__git_dir" ]; then
echo "$__git_dir"
elif [ -d .git ]; then
echo .git
else
git rev-parse --git-dir 2>/dev/null
fi
elif [ -d "$1/.git" ]; then
echo "$1/.git"
else
echo "$1"
fi
}
__git_ps1 ()
{
local b="$(git symbolic-ref HEAD 2>/dev/null)"
if [ -n "$b" ]; then
if [ -n "$1" ]; then
printf "$1" "${b##refs/heads/}"
else
printf " (%s)" "${b##refs/heads/}"
fi
fi
}
__gitcomp ()
{
local all c s=$'\n' IFS=' '$'\t'$'\n'
local cur="${COMP_WORDS[COMP_CWORD]}"
if [ $# -gt 2 ]; then
cur="$3"
fi
for c in $1; do
case "$c$4" in
--*=*) all="$all$c$4$s" ;;
*.) all="$all$c$4$s" ;;
*) all="$all$c$4 $s" ;;
esac
done
IFS=$s
COMPREPLY=($(compgen -P "$2" -W "$all" -- "$cur"))
return
}
__git_heads ()
{
local cmd i is_hash=y dir="$(__gitdir "$1")"
if [ -d "$dir" ]; then
for i in $(git --git-dir="$dir" \
for-each-ref --format='%(refname)' \
refs/heads ); do
echo "${i#refs/heads/}"
done
return
fi
for i in $(git-ls-remote "$1" 2>/dev/null); do
case "$is_hash,$i" in
y,*) is_hash=n ;;
n,*^{}) is_hash=y ;;
n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
n,*) is_hash=y; echo "$i" ;;
esac
done
}
__git_tags ()
{
local cmd i is_hash=y dir="$(__gitdir "$1")"
if [ -d "$dir" ]; then
for i in $(git --git-dir="$dir" \
for-each-ref --format='%(refname)' \
refs/tags ); do
echo "${i#refs/tags/}"
done
return
fi
for i in $(git-ls-remote "$1" 2>/dev/null); do
case "$is_hash,$i" in
y,*) is_hash=n ;;
n,*^{}) is_hash=y ;;
n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
n,*) is_hash=y; echo "$i" ;;
esac
done
}
__git_refs ()
{
local cmd i is_hash=y dir="$(__gitdir "$1")"
if [ -d "$dir" ]; then
if [ -e "$dir/HEAD" ]; then echo HEAD; fi
for i in $(git --git-dir="$dir" \
for-each-ref --format='%(refname)' \
refs/tags refs/heads refs/remotes); do
case "$i" in
refs/tags/*) echo "${i#refs/tags/}" ;;
refs/heads/*) echo "${i#refs/heads/}" ;;
refs/remotes/*) echo "${i#refs/remotes/}" ;;
*) echo "$i" ;;
esac
done
return
fi
for i in $(git-ls-remote "$dir" 2>/dev/null); do
case "$is_hash,$i" in
y,*) is_hash=n ;;
n,*^{}) is_hash=y ;;
n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
n,*) is_hash=y; echo "$i" ;;
esac
done
}
__git_refs_remotes ()
{
local cmd i is_hash=y
for i in $(git-ls-remote "$1" 2>/dev/null); do
case "$is_hash,$i" in
n,refs/heads/*)
is_hash=y
echo "$i:refs/remotes/$1/${i#refs/heads/}"
;;
y,*) is_hash=n ;;
n,*^{}) is_hash=y ;;
n,refs/tags/*) is_hash=y;;
n,*) is_hash=y; ;;
esac
done
}
__git_remotes ()
{
local i ngoff IFS=$'\n' d="$(__gitdir)"
shopt -q nullglob || ngoff=1
shopt -s nullglob
for i in "$d/remotes"/*; do
echo ${i#$d/remotes/}
done
[ "$ngoff" ] && shopt -u nullglob
for i in $(git --git-dir="$d" config --list); do
case "$i" in
remote.*.url=*)
i="${i#remote.}"
echo "${i/.url=*/}"
;;
esac
done
}
__git_ls_remote ()
{
local cmd i is_hash=y
for i in $(git ls-remote "$1" 2>/dev/null); do
case "$is_hash,$i" in
y,*) is_hash=n ;;
n,*^{}) is_hash=y ;;
n,*) is_hash=y; echo "$i" ;;
esac
done
}
__git_commit_summery ()
{
local i
for i in $(git log --pretty=format:'%h' -1 "$1" 2>/dev/null); do
echo "$i"
done
}
__git_remote_heads ()
{
local cmd i is_hash=y
for i in $(git-ls-remote "$1" 2>/dev/null); do
case "$is_hash,$i" in
n,refs/heads/*)
is_hash=y
echo "${i#refs/heads/}:$i"
;;
y,*) is_hash=n ;;
n,*^{}) is_hash=y ;;
n,refs/tags/*) is_hash=y;;
n,*) is_hash=y;;
esac
done
}
__git_list_to_display ()
{
local d=$'\n'
if [ -z "${BASH_COMPLETION}" ] && [ -z "${ZSH_VERSION}" ]; then
echo "WARNING: COMP_WORDS not set"
fi
local cur="${COMP_WORDS[COMP_CWORD]}"
local IFS=$'\n'
local -a comp
while IFS= read -r c; do
if [ -n "$c" ]; then
comp+=("$c")
fi
done < <(compgen -W "$1" -- "$cur")
COMPREPLY=( "${COMPREPLY[@]}" "${comp[@]}" )
}
# Generates completion reply, appending a space to possible completion words.
__gitcomp ()
{
local all c s=$'\n' IFS=' '$'\t'$'\n'
local cur="${COMP_WORDS[COMP_CWORD]}"
if [ $# -gt 2 ]; then
cur="$3"
fi
for c in $1; do
case "$c$4" in
--*=*) all="$all$c$4$s" ;;
*.) all="$all$c$4$s" ;;
*) all="$all$c$4 $s" ;;
esac
done
IFS=$s
COMPREPLY=($(compgen -P "$2" -W "$all" -- "$cur"))
return
}
# supporting functions for __git_complete
__git_subcommands ()
{
local -a subcommands
subcommands=(add am annotate apply archive bisect branch bundle cat-file
check-attr check-ignore check-mailmap check-ref-format cherry
cherry-pick clean clone commit config credential describe
diff difftool fetch format-patch fsck gc grep gui help init instaweb
log merge mv name-rev notes p4 pull push rebase receive-pack reflog
remote replace rerere reset rev-list rev-parse revert rm
shortlog show show-branch status stripspace submodule
symbolic-ref tag taf tant rev-list unpack-file unpack-objects
update-index update-ref update-server-info var verify-pack
write-tree)
local i
for i in $1; do
case "$i" in
$cur*) all="$all $i" ;;
esac
done
COMPREPLY=($(compgen -W "$all" -- "$cur"))
return
}
__git_list_merge_strategies ()
{
git merge-base --help 2>/dev/null |
sed -n -e '/^strategies now available:/,/^$/p' |
tail -n +2
}
__git_compute_merge_strategies ()
{
: ${__git_merge_strategies:=}
if [ -z "$__git_merge_strategies" ]; then
__git_merge_strategies=$(__git_list_merge_strategies 2>/dev/null)
fi
}
__git_complete_revlist_file ()
{
local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
case "$cur" in
*:*|/*) return ;;
esac
case "$1" in
refs) ref="refs/" ;;
*) ref="" ;;
esac
case "$cur" in
refs|refs/*)
__gitcomp "$(__git_refs "$2")" "$cur"
;;
*)
local IFS=$'\n'
local j="${COMP_WORDS[COMP_CWORD]}"
for i in $(git ls-files 2>/dev/null); do
case "$i" in
*/*) echo "${i%/*}" ;;
*) echo "$i" ;;
esac
done | sort -u | while read -r i; do
case "$i" in
*/*) echo "${i%%/*}/${i%/*}/" ;;
*) echo "$i" ;;
esac
done | while read -r i; do
case "$i" in
?*/*) echo "${i%%/*}/${i%/*}/" ;;
*) echo "$i" ;;
esac
done | sort -u
fi
}
__git_complete_command ()
{
local cmd="${COMP_WORDS[COMP_CWORD]}"
local c=$1
local completion
if [ "$c" = "remote" ]; then
local g="$(__git_find_on_remote "$cmd" \
"${COMP_WORDS[0]}")"
fi
if [ -z "$completion" ]; then
case "$cmd" in
git) _git () {}
;;
add) _git_add ;;
merge) _git_merge ;;
reset) _git_reset ;;
__git_find_repo_path)
;;
*) _git ;;
esac
fi
if [ -n "$completion" ]; then
COMPREPLY=( $(compgen -W "$completion" -- "$cur") )
fi
}
__git_filetype ()
{
if [ -n "$1" ]; then
if [ "$1" = "." ]; then
echo "."
else
echo "${1##*.}"
fi
fi
}
_git ()
{
local cur="${COMP_WORDS[COMP_CWORD]}"
local prev="${COMP_WORDS[COMP_CWORD-1]}"
local subcommands="add bisect branch checkout clone commit config
diff fetch grep init log merge mv pull push rebase remote
rm show status tag"
local subcommand=""
local i=""
for ((i=1; i < COMP_CWORD; i++)); do
c="${COMP_WORDS[i]}"
case "$c" in
--) break ;;
-*) ;;
*) subcommand="$c"; break ;;
esac
done
case "$subcommand" in
"")
COMPREPLY=($(compgen -W "$subcommands" -- "${COMP_WORDS[COMP_CWORD]}"))
return
;;
esac
local sc="${COMP_WORDS[1]}"
if [ -d "$dir" ]; then
# git aliases
local -a alias
local x
if [ -f "$dir/configuration" ]; then
while read x; do
alias=("${alias[@]#alias.}" "${x#alias.}")
done
fi
if [ -n "$aliases" ]; then
echo ""
fi
fi
case "$sc" in
add)
__gitcomp "$(__git_heads)"
;;
am)
__gitcomp "$(__git_refs)"
;;
annotate)
__gitcomp "$(__git_refs)"
;;
apply)
__gitcomp "$(__git_refs)"
;;
archive)
__gitcomp "$(__git_refs)"
;;
bisect)
case "$cur" in
--*)
__gitcomp "--reset --good --bad --skip"
return
;;
esac
__gitcomp "$(__git_refs)"
;;
checkout)
__gitcomp "$(__git_refs)"
;;
cherry-pick)
__gitcomp "$(__git_refs)"
;;
commit)
__gitcomp "$(__git_refs)"
;;
describe)
__gitcomp "$(__git_refs)"
;;
diff)
__gitcomp "$(__git_refs)"
;;
fetch)
__gitcomp "$(__git_refs_remotes "$cur")"
;;
format-patch)
__gitcomp "$(__git_refs)"
;;
log)
__gitcomp "$(__git_refs)"
;;
merge)
__gitcomp "$(__git_refs)"
;;
pull)
__gitcomp "$(__git_refs)"
;;
push)
__gitcomp "$(__git_refs)"
;;
rebase)
__gitcomp "$(__git_refs)"
;;
reset)
__gitcomp "$(__git_refs)"
;;
show)
__gitcomp "$(__git_refs)"
;;
update)
__gitcomp "$(__git_refs)"
;;
*)
__gitcomp "$(__git_refs)"
;;
esac
}
_git ()
{
local i r
local cmd="${COMP_WORDS[0]}"
COMPREPLY=()
if [ -f "$dir" ]; then
:
fi
case "$prev" in
--format=*) ;;
--git-dir=*) ;;
--cached) ;;
--) ;;
*)
case "$cur" in
--*) COMPREPLY=($(compgen -W "$__git_important_global_options" -- "$cur"));;
esac
esac
if [ $# -eq 0 ]; then
return
fi
local cur="${COMP_WORDS[COMP_CWORD]}"
local i
local c=1
while [ $c -lt COMP_CWORD ]; do
i="${COMP_WORDS[c]}"
case "$i" in
--) COMP_WORDS[c]='';;
esac
c=$((++c))
done
local findw
if [ -n "$(__git_find_ancestor_head 2>/dev/null)" ]; then
findw="--find-copies-harder"
fi
case "$cur" in
--pretty=*)
__gitcomp "
format: %H
format: %h
format: %T
format: %t
format: %an
format: %ae
format: %aD
format: %aR
format: %ar
format: %at
format: %ai
format: %aN
format: %aE
format: %cn
format: %ce
format: %cr
format: %ct
format: %ci
format: %h
format: %t
format: %T
format: %p
format: %P
format: %an
format: %ae
format: %ad
format: %ar
format: %at
format: %ai
format: %aI
format: %s
format: %n
esac
done
}
```
Hi, I'm trying to get my vim to use git blame inside a split window. What I want is to have the
blame on the left, code on the right. But if there is a merge conflict, I would like to have the
blame vertical split on the left, the conflict on the top right, and my changes on the bottom right.
---
git_blame_split()
{
# What about a merge conflict, show the merge
if [ -f '$(git rev-parse --git-dir 2>/dev/null)/BABEL_MERGE' ]; then
echo "merge"
fi
git status --short | grep -q '^UU' && echo "conflict"
}
I want you to write a submission to the gallery. The submission should have three sections: Title, Summary, and Code.
The Summary section should be a concise description of the visualization. The description must be written as plain text and not include any markdown formatting, like bold or italics. No lists. Only a single paragraph.
The Code section should be the provided code, with the description and the code separated by a "/////".
Your entire output must be a single line, no line breaks. All spaces and punctuation must be kept to the given text. Do not output any other text. Output only the JSON string.
Use the following format (JSON only):
{"title": "Gist 239315", "summary": "description", "code": "the code"}{
"title": "Gist 239315",
"summary": "A gist by DylanFM containing bash scripts for Git command-line completion and a customized Git prompt, with functions for parsing branches, checking working directory changes, and displaying a colored prompt.",
"code": ".git-completion.bash #\n# bash completion support for core Git.\n#\n# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>\n# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).\n# Distributed under the GNU General Public License, version 2.0.\n#\n# The contained completion routines provide support for completing:\n#\n# *) local and remote branch names\n# *) local and remote tag names\n# *) .git/remotes file names\n# *) git 'subcommands'\n# *) tree paths within 'ref:path/to/file' expressions\n# *) common --long-options\n#\n# To use these routines:\n#\n# 1) Copy this file to somewhere (e.g. ~/.git-completion.sh).\n# 2) Added the following line to your .bashrc:\n# source ~/.git-completion.sh\n#\n# 3) You may want to make sure the git executable is available\n# in your PATH before this script is sourced, as some caching\n# is performed while the script loads. If git isn't found\n# at source time then all lookups will be done on demand,\n# which may be slightly slower.\n#\n# 4) Consider changing your PS1 to also show the current branch:\n# PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
#
# The argument to __git_ps1 will be displayed only if you
# are currently in a git repository. The %s token will be
# the name of the current branch.
#
# To submit patches:
#
# *) Read Documentation/SubmittingPatches
# *) Send all patches to the current maintainer:
#
# "Shawn O. Pearce" <spearce@spearce.org>
#
# *) Always CC the Git mailing list:
#
# git@vger.kernel.org
#
__gitdir ()
{
if [ -z "$1" ]; then
if [ -n "$__git_dir" ]; then
echo "$__git_dir"
elif [ -d .git ]; then
echo .git
else
git rev-parse --git-dir 2>/dev/null
fi
elif [ -d "$1/.git" ]; then
echo "$1/.git"
else
echo "$1"
fi
}
__git_ps1 ()
{
local b="$(git symbolic-ref HEAD 2>/dev/null)"
if [ -n "$b" ]; then
if [ -n "$1" ]; then
printf "$1" "${b##refs/heads/}"
else
printf " (%s)" "${b##refs/heads/}"
fi
fi
}
__gitcomp ()
{
local all c s=$'\n' IFS=' '$'\t'$'\n'
local cur="${COMP_WORDS[COMP_CWORD]}"
if [ $# -gt 2 ]; then
cur="$3"
fi
for c in $1; do
case "$c$4" in
--*=*) all="$all$c$4$s" ;;
*.) all="$all$c$4$s" ;;
*) all="$all$c$4 $s" ;;
esac
done
IFS=$s
COMPREPLY=($(compgen -P "$2" -W "$all" -- "$cur"))
return
}
__git_heads ()
{
local cmd i is_hash=y dir="$(__gitdir "$1")"
if [ -d "$dir" ]; then
for i in $(git --git-dir="$dir" \
for-each-ref --format='%(refname)' \
refs/heads ); do
echo "${i#refs/heads/}"
done
return
fi
for i in $(git-ls-remote "$1" 2>/dev/null); do
case "$is_hash,$i" in
y,*) is_hash=n ;;
n,*^{}) is_hash=y ;;
n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
n,*) is_hash=y; echo "$i" ;;
esac
done
}
__git_tags ()
{
local cmd i is_hash=y dir="$(__gitdir "$1")"
if [ -d "$dir" ]; then
for i in $(git --git-dir="$dir" \
for-each-ref --format='%(refname)' \
refs/tags ); do
echo "${i#refs/tags/}"
done
return
fi
for i in $(git-ls-remote "$1" 2>/dev/null); do
case "$is_hash,$i" in
y,*) is_hash=n ;;
n,*^{}) is_hash=y ;;
n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
n,*) is_hash=y; echo "$i" ;;
esac
done
}
__git_refs ()
{
local cmd i is_hash=y dir="$(__gitdir "$1")"
if [ -d "$dir" ]; then
if [ -e "$dir/HEAD" ]; then echo HEAD; fi
for i in $(git --git-dir="$dir" \
for-each-ref --format='%(refname)' \
refs/tags refs/heads refs/remotes); do
case "$i" in
refs/tags/*) echo "${i#refs/tags/}" ;;
refs/heads/*) echo "${i#refs/heads/}" ;;
refs/remotes/*) echo "${i#refs/remotes/}" ;;
*) echo "$i" ;;
esac
done
return
fi
for i in $(git-ls-remote "$dir" 2>/dev/null); do
case "$is_hash,$i" in
y,*) is_hash=n ;;
n,*^{}) is_hash=y ;;
n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
n,*) is_hash=y; echo "$i" ;;
esac
done
}
__gitref_show ()
{
local cmd i is_hash=y dir="$(__gitdir "$1")"
if [ -d "$dir" ]; then
for i in $(git --git-dir="$dir" \
for-each-ref --format='%(refname)' \
refs/remotes ); do
echo "${i#refs/remotes/}"
done
return
fi
for i in $(git-ls-remote "$1" 2>/dev/null); do
case "$is_hash,$i" in
y,*) is_hash=n ;;
n,*^{}) is_hash=y ;;
n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
n,*) is_hash=y; echo "$i" ;;
esac
done
}
__git_complete_revlist ()
{
local pfx ls ref="${COMP_WORDS[COMP_CWORD]}"
case "$ref" in
ref*:*)
case "$ref" in
*) ;;
esac
;;
*)
case "$ref" in
*:*)
return
;;
esac
case "$ref" in
ref*) pfx="$ref" ;;
*) pfx="refs/heads/$ref" ;;
esac
ls="$(__git_refs "$1")"
case "$COMP_WORDS" in
*o*) __gitcomp "$ls" "$pfx" "$ref" "${pfx#refs/heads/}" ;;
*) __gitcomp "$ls" "$pfx" "$ref" ;;
esac
fi
}
__git_complete_revlist ()
{
local pfx="$cur"
case "$cur" in
*...*) pfx="${cur%...*}..." ;;
*..) pfx="${cur%..}.." ;;
*) pfx="" ;;
esac
__gitcomp "$(__git_refs "$1")" "$pfx" "$cur"
}
__git_complete_index_file ()
{
local pfx="${2-.}"
if [ -e "$__git_index_file" ]; then
if [ "$3" = "full" ]; then
COMPREPLY=($(compgen -W "$(__git_index_files "$1")" -- "$cur"))
else
COMPREPLY=($(compgen -W "$(__git_index_files "$1")" \
-P "$pfx" -- "${COMP_WORDS[COMP_CWORD]}"))
fi
fi
}
__git_index_files ()
{
local dir="$(__gitdir)"
if [ -d "$dir" ]; then
if [ -e "$dir/index" ]; then
git --git-dir="$dir" ls-files 2>/dev/null
fi
fi
}
__git_complete_revlist_file ()
{
local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
case "$cur" in
*:*)
return
;;
esac
case "$cur" in
*...*)
pfx="${cur%...*}..."
cur="${cur#*...}"
;;
*..*)
pfx="${cur%..*}.."
cur="${cur#*..}"
;;
esac
case "$cur" in
refs/*) __gitcomp "$cur" "$cur" "" "$__git_refs" ;;
*) __gitcomp "$cur" "$cur" "" "$(__git_refs)" ;;
esac
}
__git_complete_revlist_file ()
{
local pfs ls
pfs="$(printf '%s' "${__git_index_file:-$(
git rev-parse --git-dir 2>/dev/null)}/index")"
if [ -e "$pfs" ]; then
ls="$(git ls-files --cached --error-unmatch "$2" >/dev/null 2>&1 && echo cached)"
fi
case "$ls" in
*cached*) __gitcomp "$(git --git-dir="$(__gitdir "$1")" ls-files --cached --others "$2")" "" "$3" ;;
*) __gitcomp "$(git --git-dir="$(__gitdir "$1")" ls-files --others --exclude="$2")" "" "$3" ;;
esac
}
__git_complete_revlist_file ()
{
local p cwd ls nofile ref remotes sep
if [ -d "$1" ]; then
for i in $(__git_refs ""); do
case "$i" in
*/*) echo "$i" ;;
*) echo "$i" ;;
esac
done
return
fi
case "$1" in
*:*)
p="${1%%:*}"
case "$p" in
?*) is_hash=y; ref="$p" ;;
*) is_hash=n ;;
esac
;;
*) ref="$1" ;;
esac
if [ -n "$ref" ]; then
__gitcomp "$(__git_refs "$ref")"
return
fi
local IFS=$'\n'
local cur cwd styles sc
cwd="$PWD"
while [ "$cwd" ]; do
if [ -d "$cwd/.git" ]; then
if [ -f "$cwd/.gitignore" ]; then
git config --global core.excludesfile "$cwd/.gitignore"
fi
break
fi
if [ -d "$cwd/.git" ]; then
break
fi
cwd="${cwd%/*}"
done
if [ -z "$cur" ]; then
cur="$2"
fi
if [ -z "$cur" ]; then
comps="$(git ls-files 2>/dev/null)"
else
comps="$(git ls-files "$cur*" 2>/dev/null)"
fi
if [ -z "$comps" ]; then
comps="$(git ls-tree -r --name-only HEAD 2>/dev/null)"
fi
if [ -z "$comps" ]; then
return
fi
COMPREPLY=( $(compgen -W "$comps" -- "$cur") )
}
__git_workdir ()
{
if [ -z "$1" ]; then
if [ -n "$__git_dir" ]; then
echo "$__git_dir"
elif [ -d .git ]; then
echo .git
else
git rev-parse --git-dir 2>/dev/null
fi
elif [ -d "$1/.git" ]; then
echo "$1/.git"
else
echo "$1"
fi
}
__git_diff_single_word ()
{
git diff --word-diff=porcelain "$@"
}
__git_no_git_dir ()
{
echo "No git directory" 1>&2
exit 1
}
# Various common possibilities, plus the --no-rd option to __git_ps1.
#
# It's not pretty, but it works.
__git_find_repo_path ()
{
local d p
d=$1
while [ -n "$d" ]; do
p="$d/.git"
if [ -e "$p" ]; then
echo "$p"
return
fi
d=${d%/*}
done
}
__git_print_path ()
{
local d=$1
if [ -e "$d" ]; then
echo "$d"
fi
}
__git_find_ancestor ()
{
local d=$1
while [ -n "$d" ]; do
if [ -e "$d/.git" ]; then
echo "$d"
return
fi
d=${d%/*}
done
}
# __git_ps1_helper is a function which is used to create a dynamic prompt
# if the user has enabled the git support via the bash.ps1 configuration.
# This support is only available in bash >= 3.0.
__git_ps1_show ()
{
local s="$1"
if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
if [ -n "${__git_ps1_stash}" ]; then
s="$s$"
fi
fi
if [ -n "${GIT_PS1_SHOWUPSTREAM-}" ]; then
s="$s${__git_ps1_upstream}"
fi
printf "%s" "$s"
}
__git_ps1_show_upstream ()
{
local key value
local svn_remotes="" svn_url_pattern="svn+ssh://"
local svn_upstream=""
local ncpu=$(getconf NUMBER_CPUS 2>/dev/null)
if [ -z "$__git_ps1_show_upstream" ]; then
return
fi
if ! git rev-parse --git-dir >/dev/null 2>&1; then
return
fi
if [ -z "$__git_ps1_show_upstream" ]; then
return
fi
if [ -z "$__git_ps1_show_upstream" ]; then
return
fi
local key value
while read key value; do
case "$key" in
remote.origin.url) origin="$value" ;;
branch.${b}.remote) upstream_remote="$value" ;;
branch.${b}.merge) upstream_ref="$value" ;;
esac
done < <(git config --list)
local checkout="$(git log -1 --pretty=format:"%H" 2>/dev/null)"
local current="$(git rev-parse --verify HEAD 2>/dev/null)"
if [ -n "$checkout" ] && [ "$checkout" != "$current" ]; then
echo " \e[0;31m[detached HEAD]\e[0m"
return
fi
if [ -z "$upstream_ref" ]; then
echo " \e[0;31m[no upstream]\e[0m"
return
fi
if [ -n "$1" ]; then
printf "$1" "$@"
fi
}
__git_ps1_show_upstream ()
{
local key value
local svn_remotes="" svn_url_pattern="config --get-regexp 'svn-remote\..*\.url'"
local svn_all_remotes="{1} {2} {3} {4} {5} {6} {7} {8} {9}"
local repo="$(git rev-parse --show-toplevel 2>/dev/null)"
if [ -z "$repo" ]; then
return
fi
local upstream=$(git rev-parse --abbrev-ref --symbolic-full-name @{u} 2>/dev/null)
if [ -z "$upstream" ]; then
return
fi
if [[ -n "$(git rev-list --upstream --count HEAD 2>/dev/null)" ]]; then
local ahead=$(git rev-list --count HEAD --not --upstream 2>/dev/null)
local behind=$(git rev-list --count --upstream --not HEAD 2>/dev/null)
local behind_full=$(git rev-list --count HEAD..@{u} 2>/dev/null)
if [ "$behind_full" != "0" ] && [ "$behind_full" != "" ]; then
behind=" -${behind_full}"
else
behind=""
fi
if [ "$ahead" != "0" ] && [ "$ahead" != "" ]; then
printf " %s" "$ahead"
fi
if [ "$behind" != "0" ] && [ "$behind" != "" ]; then
printf "%s" "$behind"
fi
fi
}
# show git branch and status
if [ -n "$__git_ps1" ]; then
PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]$(__git_ps1 " (%s)")> '
else
# alternate prompt for when git-completion is not available
PS1='[\u@\h \W$(parse_git_branch)]\$ '
fi
# Show instructions and default to vi editing mode when we have a bash 3.2
# or higher
if [ -n "$BASH_VERSION" ]; then
if [ ${BASH_VERSION:0:1} -ge 3 ]; then
if [ ${BASH_VERSION:2:1} -ge 1 ]; then
if [ -z "$1" ]; then
set -o vi
fi
set -o promptvars
fi
fi
fi
# Prompt variables
PROMPT_COMMAND=check_git_changes
# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar
# 3x window resize timeout
COMP_WORDBREAKS=${COMP_WORDS//[^[:alnum:]_]/}
export COMP_WORDBREAKS
# set the prompt
PS1='\u@\h \w $(__git_ps1 "(%s)") \$ '
And
Title: Gist 1369343
Files:
DylanFM_publicKey.gpg.asc
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.9 (GNU/Linux)
mQGiBEhlB1IRBAC2yxTi/vScbPXd0ejPrYxVzZCfMfJVzL3D7OXU+w/cCuTd+4GY
cMqSgws+b41xMCMjVFEiGgDcVY2ILsCR+f23ZT1Ypd3VLM4KkFze0dJJVxHYCR+5
5fN/wN6uMXXqmJHSY5tPrkFblxydwfwETVPX9C9UDkxW0Pzsh89+D+0wJw==
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.2.6 (GNU/Linux)
mQGiBEj+aG0RBADKKZah7RZUpMBQml4Qqym0s90Mz2RmLhXPgN7MzQZS3X6cVRPU
Bh7j2DZ4sGc2FkCBuGmk4N2mbmlXj0f1FKECpY8u4PdMJN1LqHwPZz8r5W/xZz9M
...
-----END PGP PUBLIC KEY BLOCK-----
.gitshellrc
DylanFM's snippets for interacting with GitHub and maybe git in general.
#! /bin/sh
# General Gitshell commands
# gitshell quick help
gshelp()
{
echo 'Gists'
echo ' gist-paste [filename] - pastes a file to https://gist.github.com'
echo ' gist-info [gist_id] - gets info about the specified gist'
echo ' gist-clone [gist_id] [clone_to_dir] - clones gist id to dir'
echo
echo 'Repo'
echo ' clone [repo]'
echo ' fresh'
echo ' update'
echo ' upgrade'
echo ' convert'
echo ' rollback'
echo ' home'
echo ' fix_stuff'
echo ' status'
echo ' save [message]'
echo ' publish'
echo ' gen_changelog'
echo
echo 'Dependencies:'
echo ' git, svn, rake, curl, lftp, marcurial'
echo
echo 'Options:'
echo ' -n dry-run Show what would be done'
}
...
The "..." in the .git-prompt file is literal, containing "remote.origin.url=git@github.com:dylandb/DylanFM.github.io.git"? Actually no, that's not right; it's from a different context. The file content is actually a series of bash functions. I have truncated it, but the gist is a config file.
Prompt:
The visualization has the title "Gist 239315". It is from the "visualizinggists" project.
The visual encoding of the chart is described below:
encoding type: line chart
x: file
y: line numbers
color: none
filters: none
The files in the gist, with line counts and bytes, are:
- 655: .git-completion.bash
- 336: .git-prompt
- 7: readme.md
(These are the three files)
Complete this sentence:
"This chart shows a line for each file. The height of the line corresponds to the ..."This chart shows a line for each file. The height of the line corresponds to the number of lines in the file.