Guest User

Untitled

a guest
Oct 19th, 2018
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 KB | None | 0 0
  1. # Drop this file somewhere and then add
  2. # '. git-profile-additions.sh' in your .bashrc or whatever.
  3.  
  4. # Set these configs in git.
  5. export GITHUB_TOKEN=$(git config --get github.token)
  6. export GITHUB_USER=$(git config --get github.user)
  7. export GIT_COMMITTER_NAME=${GITHUB_USER:-$(git config --get user.name)}
  8. export GIT_COMMITTER_EMAIL=$(git config --get user.email)
  9. export GIT_AUTHOR_NAME=${GITHUB_USER:-$(git config --get user.name)}
  10. export GIT_AUTHOR_EMAIL=$(git config --get user.email)
  11.  
  12. alias gci="git commit"
  13. alias gap="git add -p"
  14. alias gau="git add -u"
  15. alias gst="git status"
  16. alias glg="git lg"
  17. alias gti="git"
  18. alias gci-am="git commit -am"
  19.  
  20. alias maek="make"
  21. alias meak="make"
  22. alias meak="make"
  23.  
  24. alias authors="(echo "${GIT_AUTHOR_NAME} ${GIT_AUTHOR_EMAIL}"; git authors | grep -v "${GIT_AUTHOR_NAME}" | perl -pi -e 's|\([^\)]*\)||g' | sort | uniq)"
  25.  
  26. # for use in the node repo
  27. alias nodeauthors="git log --pretty='format:%ae %an' | tail -r | awk -f tools/updateAuthors.awk"
  28.  
  29. gam () {
  30. git ci -am "$@"
  31. }
  32.  
  33. # gist and copy a git format-patch of the top commit
  34. cpg () {
  35. rm *patch
  36. git format-patch HEAD^
  37. gist *patch | pbcopy
  38. }
  39.  
  40. # git-style diff without it having to be a git thing
  41. alias gdiff='git diff --no-index --color'
  42.  
  43. # Now that most markdowns support ```, the ind/und
  44. # is not so relevant, but it's still handy for emails
  45. # and stuff like that.
  46. alias pbind="pbpaste | sed 's|^| |g' | pbcopy"
  47. alias pbund="pbpaste | sed 's|^ ||g' | pbcopy"
  48.  
  49. # convert to text.
  50. alias pbtxt="pbpaste | pbcopy"
  51.  
  52. # paste to gist command, then copy and display the url
  53. pbgist () {
  54. pbpaste | gist "$@" | pbcopy
  55. pbpaste
  56. }
  57.  
  58. ghadd () {
  59. local me="$(git config --get github.user)"
  60. [ "$me" == "" ] && echo "Please enter your github name as the github.user git config." && return 1
  61. # like: "git@github.com:$me/$repo.git"
  62. local mine="$( git config --get remote.origin.url )"
  63. local repo="${mine/git@github.com:$me\//}"
  64. local nick="$1"
  65. local who="$2"
  66. [ "$who" == "" ] && who="$nick"
  67. [ "$who" == "" ] && ( echo "usage: ghadd [nick] <who>" >&2 ) && return 1
  68. # eg: git://github.com/isaacs/jack.git
  69. local theirs="git://github.com/$who/$repo"
  70. git remote add "$nick" "$theirs"
  71. git fetch -a "$nick"
  72. }
  73.  
  74. # Add the github origin remote
  75. gho () {
  76. local me="$(git config --get github.user)"
  77. [ "$me" == "" ] && \
  78. echo "Please enter your github name as the github.user git config." && \
  79. return 1
  80. # like: "git@github.com:$me/$repo.git"
  81. local name="${1:-$(basename "$PWD")}"
  82. local repo="git@github.com:$me/$name"
  83. git remote add "origin" "$repo"
  84. git fetch -a "$origin"
  85. }
  86.  
  87. gpa () {
  88. git push --all "$@"
  89. }
  90.  
  91. gpt () {
  92. git push --tags "$@"
  93. }
  94.  
  95. gps () {
  96. gpa "$@"
  97. gpt "$@"
  98. }
  99.  
  100. # Look up any ref's sha, and also copy it for pasting into bugs and such
  101. # gsh <commit-ish> --> copies 'c0ffeedecafbaddeadbeef15aac...' to the
  102. gsh () {
  103. local sha
  104. sha=$(git show ${1-HEAD} | grep commit | head -n1 | awk '{print $2}' | xargs echo -n)
  105. echo -n $sha | pbcopy
  106. echo $sha
  107. }
  108.  
  109. npmgit () {
  110. local name=$1
  111. git clone $(npm view $name repository.url) $name
  112. }
  113.  
  114. gf () {
  115. git fetch -a "$1"
  116. }
  117.  
  118. # 1. Bump package.json version
  119. # 2. run 'gv' to make a new commit and signed tag
  120. # TODO: Get this functionality into the 'npm version' command.
  121. gv () {
  122. local v=$(npm ls -pl | head -1 | awk -F: '{print $2}' | awk -F@ '{print $2}')
  123. git ci -am $v && git tag -sm $v $v
  124. }
  125.  
  126. # Pull a submodule checked out into ./node_modules/xyz
  127. nsp () {
  128. npm explore $1 -- git pull origin master
  129. }
  130.  
  131. # I can't type
  132. # turn 'gi tadd foo' to 'git add foo'
  133. gi () {
  134. local c=${1}
  135. cmd=("$@")
  136. cmd[1]=${c:1}
  137. cmd[0]=git
  138. "${cmd[@]}"
  139. }
  140.  
  141. # a context-sensitive rebasing git pull.
  142. # usage:
  143. # ghadd someuser # add the github remote account
  144. # git checkout somebranch
  145. # gpm someuser # similar to "git pull someuser somebranch"
  146. # Remote branch is rebased, and local changes stashed and reapplied if possible.
  147.  
  148. gp () {
  149. local s
  150. local head
  151. s=$(git stash 2>/dev/null)
  152. head=$(basename $(git symbolic-ref HEAD 2>/dev/null) 2>/dev/null)
  153. if [ "" == "$head" ]; then
  154. echo_error "Not on a branch, can't pull"
  155. return 1
  156. fi
  157. git fetch -a $1
  158. git pull --rebase $1 "$head"
  159. [ "$s" != "No local changes to save" ] && git stash pop
  160. }
Add Comment
Please, Sign In to add comment