From 0a797fb6206e5e83e0e0839dc305f38c55e42159 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Sat, 17 Nov 2012 11:41:08 +1300 Subject: [PATCH 01/25] Provide X-compatible find_binary function that finds a binary for a given command. Works with zsh/bash --- lib/git/shell_shortcuts.sh | 10 +++++----- lib/scm_breeze.sh | 14 +++++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/git/shell_shortcuts.sh b/lib/git/shell_shortcuts.sh index 532eb61..e82803e 100644 --- a/lib/git/shell_shortcuts.sh +++ b/lib/git/shell_shortcuts.sh @@ -29,15 +29,15 @@ if [ "$shell_command_wrapping_enabled" = "true" ] || [ "$bash_command_wrapping_e if [ "${scmbDebug:-}" = "true" ]; then echo "SCMB: $cmd is an alias"; fi # Store original alias local original_alias="$(whence $cmd)" - # Remove alias, so that which can return binary + # Remove alias, so that we can find binary unalias $cmd # Detect original $cmd type, and escape case "$(type $cmd 2>&1)" in # Escape shell builtins with 'builtin' *'is a shell builtin'*) local escaped_cmd="builtin $cmd";; - # Get full path for files with 'which' - *) local escaped_cmd="$(\which $cmd)";; + # Get full path for files with 'find_binary' function + *) local escaped_cmd="$(find_binary $cmd)";; esac # Expand original command into full path, to avoid infinite loops @@ -62,8 +62,8 @@ if [ "$shell_command_wrapping_enabled" = "true" ] || [ "$bash_command_wrapping_e *) if [ "${scmbDebug:-}" = "true" ]; then echo "SCMB: $cmd is an executable file"; fi # Otherwise, command is a regular script or binary, - # and the full path can be found from 'which' - alias $cmd="exec_scmb_expand_args $(\which $cmd)";; + # and the full path can be found with 'find_binary' function + alias $cmd="exec_scmb_expand_args $(find_binary $cmd)";; esac done # Clean up diff --git a/lib/scm_breeze.sh b/lib/scm_breeze.sh index 0dc30ce..8cb2b1a 100644 --- a/lib/scm_breeze.sh +++ b/lib/scm_breeze.sh @@ -12,11 +12,15 @@ disable_nullglob() { if [ $shell = "zsh" ]; then unsetopt NULL_GLOB; else shopt # Alias wrapper that ignores errors if alias is not defined. _alias(){ alias "$@" 2> /dev/null; } -if [ $shell = "zsh" ]; then - export GIT_BINARY=$(type -p git | sed 's/git is //' | head -1) -else - export GIT_BINARY=$(type -P git) -fi +find_binary(){ + if [ $shell = "zsh" ]; then + type -p "$1" | sed "s/$1 is //" | head -1 + else + type -P "$1" + fi +} + +export GIT_BINARY=$(find_binary git) # Updates SCM Breeze from GitHub. update_scm_breeze() { From 3dcf934a75fbafe6ea32a0bf27353a6a06b34f2b Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Sat, 17 Nov 2012 11:42:33 +1300 Subject: [PATCH 02/25] Use builtin type to protect against aliases --- lib/scm_breeze.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/scm_breeze.sh b/lib/scm_breeze.sh index 8cb2b1a..7d84148 100644 --- a/lib/scm_breeze.sh +++ b/lib/scm_breeze.sh @@ -14,9 +14,9 @@ _alias(){ alias "$@" 2> /dev/null; } find_binary(){ if [ $shell = "zsh" ]; then - type -p "$1" | sed "s/$1 is //" | head -1 + builtin type -p "$1" | sed "s/$1 is //" | head -1 else - type -P "$1" + builtin type -P "$1" fi } From 963de3b7aae1712667cd07eb9749818a1625ca63 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Sat, 17 Nov 2012 11:45:26 +1300 Subject: [PATCH 03/25] Handle "aliased to" for OS X Terminal.app ... --- lib/git/shell_shortcuts.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/git/shell_shortcuts.sh b/lib/git/shell_shortcuts.sh index e82803e..2cac99a 100644 --- a/lib/git/shell_shortcuts.sh +++ b/lib/git/shell_shortcuts.sh @@ -25,7 +25,7 @@ if [ "$shell_command_wrapping_enabled" = "true" ] || [ "$bash_command_wrapping_e *'not found'*) if [ "${scmbDebug:-}" = "true" ]; then echo "SCMB: $cmd not found!"; fi;; - *'is aliased to'*|*'is an alias for'*) + *'aliased to'*|*'is an alias for'*) if [ "${scmbDebug:-}" = "true" ]; then echo "SCMB: $cmd is an alias"; fi # Store original alias local original_alias="$(whence $cmd)" From bc969b3e6f58cf24ea4b0f9c9bdc673405b5ed64 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Sat, 17 Nov 2012 11:49:46 +1300 Subject: [PATCH 04/25] Fixed tests --- test/lib/git/shell_shortcuts_test.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/lib/git/shell_shortcuts_test.sh b/test/lib/git/shell_shortcuts_test.sh index e5c860e..f1863e7 100755 --- a/test/lib/git/shell_shortcuts_test.sh +++ b/test/lib/git/shell_shortcuts_test.sh @@ -17,8 +17,9 @@ else shopt -s expand_aliases fi -# Load test helpers +# Load test helpers and core functions source "$scmbDir/test/support/test_helper.sh" +source "$scmbDir/lib/scm_breeze.sh" # Setup #----------------------------------------------------------------------------- From 2ef3776fe132a779ad657b976035d1d56677ed79 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Wed, 28 Nov 2012 19:40:38 +1300 Subject: [PATCH 05/25] git_branch_delete_all should take '-f' arg to use -D arg --- lib/git/tools.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/git/tools.sh b/lib/git/tools.sh index 8493517..45fee66 100644 --- a/lib/git/tools.sh +++ b/lib/git/tools.sh @@ -129,11 +129,14 @@ fi # Delete a git branch from local, cached remote and remote server git_branch_delete_all() { if [ -z "$1" ]; then - echo "Usage: git_branch_delete_all branch" + echo "Usage: git_branch_delete_all branch (-f forces deletion of unmerged branches.)" return fi - $_git_cmd branch -D $1 - $_git_cmd branch -D -r origin/$1 + local opt="-d" + if [ "$2" = '-f' ] || [ "$2" = '--force' ]; then opt="-D"; fi + + $_git_cmd branch $opt $1 + $_git_cmd branch $opt -r origin/$1 $_git_cmd push origin :$1 } From cd4fb8b07990bff16884e36aa5de9af2714baf14 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Tue, 4 Dec 2012 13:40:47 +1300 Subject: [PATCH 06/25] Added git push -f alias --- git.scmbrc.example | 1 + lib/git/aliases.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/git.scmbrc.example b/git.scmbrc.example index 08f685b..bac392e 100644 --- a/git.scmbrc.example +++ b/git.scmbrc.example @@ -55,6 +55,7 @@ git_fetch_all_alias="gfa" git_fetch_and_rebase_alias="gfr" git_pull_alias="gpl" git_push_alias="gps" +git_push_force_alias="gpsf" git_pull_then_push_alias="gpls" git_status_original_alias="gst" git_status_short_alias="gss" diff --git a/lib/git/aliases.sh b/lib/git/aliases.sh index a7d3bb9..636c70d 100644 --- a/lib/git/aliases.sh +++ b/lib/git/aliases.sh @@ -106,6 +106,7 @@ if [ "$git_setup_aliases" = "yes" ]; then __git_alias "$git_checkout_branch_alias" "git" 'checkout' "-b" __git_alias "$git_pull_alias" "git" 'pull' __git_alias "$git_push_alias" "git" 'push' + __git_alias "$git_push_force_alias" "git" 'push' '-f' __git_alias "$git_status_original_alias" "git" 'status' # (Standard git status) __git_alias "$git_status_short_alias" "git" 'status' '-s' __git_alias "$git_clean_alias" "git" "clean" From 9822603e9c1e0bfbc2569d8c557ba03c176ef5b2 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Wed, 5 Dec 2012 22:18:00 +1300 Subject: [PATCH 07/25] Use sed -E for GNU/BSD compatibile regexs --- lib/git/shell_shortcuts.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/git/shell_shortcuts.sh b/lib/git/shell_shortcuts.sh index 2cac99a..f7ed845 100644 --- a/lib/git/shell_shortcuts.sh +++ b/lib/git/shell_shortcuts.sh @@ -11,7 +11,7 @@ if [ "$shell_command_wrapping_enabled" = "true" ] || [ "$bash_command_wrapping_e # Do it in a function so we don't bleed variables function _git_wrap_commands() { # Define 'whence' for bash, to get the value of an alias - type whence > /dev/null 2>&1 || function whence() { type "$@" | sed -e "s/.*is aliased to \`//" -e "s/'$//"; } + type whence > /dev/null 2>&1 || function whence() { type "$@" | sed -E -e "s/.*is aliased to \`//" -e "s/'$//"; } local cmd='' for cmd in $(echo $scmb_wrapped_shell_commands); do if [ "${scmbDebug:-}" = "true" ]; then echo "SCMB: Wrapping $cmd..."; fi @@ -41,14 +41,14 @@ if [ "$shell_command_wrapping_enabled" = "true" ] || [ "$bash_command_wrapping_e esac # Expand original command into full path, to avoid infinite loops - local expanded_alias="$(echo $original_alias | sed "s%\(^\| \)$cmd\($\| \)%\\1$escaped_cmd\\2%")" + local expanded_alias="$(echo $original_alias | sed -E "s%(^| )$cmd($| )%\\1$escaped_cmd\\2%")" # Wrap previous alias with escaped command alias $cmd="exec_scmb_expand_args $expanded_alias";; *'is a'*'function'*) if [ "${scmbDebug:-}" = "true" ]; then echo "SCMB: $cmd is a function"; fi # Copy old function into new name - eval "$(declare -f $cmd | sed "s/^$cmd ()/__original_$cmd ()/")" + eval "$(declare -f $cmd | sed -E "s/^$cmd \(\)/__original_$cmd ()/")" # Remove function unset -f $cmd # Create wrapped alias for old function @@ -122,7 +122,7 @@ function ls_with_file_shortcuts { puts o.lines.map{|l|l.sub(re){|m|\"%s%-#{u}s %-#{g}s%#{s}s \"%[\$1,*\$3.split]}}" } - ll_output=$(echo "$ll_output" | \sed "s/ $USER/ $(/bin/cat $HOME/.user_sym)/g" | rejustify_ls_columns) + ll_output=$(echo "$ll_output" | \sed -E "s/ $USER/ $(/bin/cat $HOME/.user_sym)/g" | rejustify_ls_columns) fi if [ "$(echo "$ll_output" | wc -l)" -gt "50" ]; then From 242d891fcd81b490168dacef9662b1e83e5aae85 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Mon, 10 Dec 2012 23:12:13 +1300 Subject: [PATCH 08/25] Wrap first __git_ignore arg in quotes in case blank --- lib/git/tools.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/git/tools.sh b/lib/git/tools.sh index 45fee66..94bd3b6 100644 --- a/lib/git/tools.sh +++ b/lib/git/tools.sh @@ -61,7 +61,7 @@ git_exclude() { # Exclude basename of file __git_exclude_basename() { - __git_ignore $(basename "$1") ".git/info/exclude" + __git_ignore "$(basename "$1")" ".git/info/exclude" } git_exclude_basename() { exec_scmb_expand_args __git_exclude_basename $@ From 42a58329165983406d48dbf46927a9a983250d5e Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Mon, 10 Dec 2012 23:17:54 +1300 Subject: [PATCH 09/25] Added 'git tag' alias (gt) --- git.scmbrc.example | 1 + lib/git/aliases.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/git.scmbrc.example b/git.scmbrc.example index bac392e..0a36c0a 100644 --- a/git.scmbrc.example +++ b/git.scmbrc.example @@ -82,6 +82,7 @@ git_log_stat_alias="gls" git_log_graph_alias="glg" git_show_alias="gsh" git_show_summary="gsm" # (gss taken by git status short) +git_tag_alias="gt" # Git Keyboard Shortcuts diff --git a/lib/git/aliases.sh b/lib/git/aliases.sh index 636c70d..0d0080b 100644 --- a/lib/git/aliases.sh +++ b/lib/git/aliases.sh @@ -120,6 +120,7 @@ if [ "$git_setup_aliases" = "yes" ]; then __git_alias "$git_cherry_pick_alias" "git" 'cherry-pick' __git_alias "$git_show_alias" "git" 'show' __git_alias "$git_show_summary" "git" 'show' '--summary' + __git_alias "$git_tag_alias" "git" 'tag' # Compound/complex commands From aa7dd471b5d1c45c3d70a7de616fef11ed61a798 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Sat, 15 Dec 2012 08:49:28 +1300 Subject: [PATCH 10/25] Also expand args for git rebase x, where x is a shortcut to a branch --- lib/git/aliases.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/git/aliases.sh b/lib/git/aliases.sh index 0d0080b..41db79f 100644 --- a/lib/git/aliases.sh +++ b/lib/git/aliases.sh @@ -24,9 +24,9 @@ if type hub > /dev/null 2>&1; then export _git_cmd="hub"; fi # Create 'git' function that calls hub if defined, and expands all numeric arguments function git(){ - # Only expand args for a subset of git commands + # Only expand args for git commands that deal with paths or branches case $1 in - checkout|commit|reset|rm|blame|diff|add|log) + checkout|commit|reset|rm|blame|diff|add|log|rebase) exec_scmb_expand_args "$_git_cmd" "$@";; branch) _scmb_git_branch_shortcuts "${@:2}";; From 6d297aecba4459c042709ab061be33277a3238ae Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Fri, 21 Dec 2012 10:42:14 +1300 Subject: [PATCH 11/25] Wrap $@ in double quotes to preserve blank args --- lib/git/tools.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/git/tools.sh b/lib/git/tools.sh index 94bd3b6..0c62e72 100644 --- a/lib/git/tools.sh +++ b/lib/git/tools.sh @@ -50,7 +50,7 @@ __git_ignore() { } # Always expand args git_ignore() { - exec_scmb_expand_args __git_ignore $@ + exec_scmb_expand_args __git_ignore "$@" } # Add one git ignore rule, just for your machine @@ -64,7 +64,7 @@ __git_exclude_basename() { __git_ignore "$(basename "$1")" ".git/info/exclude" } git_exclude_basename() { - exec_scmb_expand_args __git_exclude_basename $@ + exec_scmb_expand_args __git_exclude_basename "$@" } From 8ba76f1cbf7f3bcfe5887f2ad6decba0e6faf079 Mon Sep 17 00:00:00 2001 From: Andy Zhang Date: Thu, 6 Dec 2012 23:47:41 -0800 Subject: [PATCH 12/25] Add "gdw" for git diff --word-diff * Sometimes helpful to see changes inline * Potential to tweak further with better regex (maybe detect similar char types so diff can be more granular) --- git.scmbrc.example | 1 + lib/git/aliases.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/git.scmbrc.example b/git.scmbrc.example index 0a36c0a..7fce17c 100644 --- a/git.scmbrc.example +++ b/git.scmbrc.example @@ -47,6 +47,7 @@ git_reset_hard_alias="grsh" git_rm_alias="grm" git_blame_alias="gbl" git_diff_alias="gd" +git_diff_word_alias="gdw" git_diff_cached_alias="gdc" # 3. Standard commands git_clone_alias="gcl" diff --git a/lib/git/aliases.sh b/lib/git/aliases.sh index 41db79f..8791bd9 100644 --- a/lib/git/aliases.sh +++ b/lib/git/aliases.sh @@ -94,6 +94,7 @@ if [ "$git_setup_aliases" = "yes" ]; then __git_alias "$git_rm_alias" "git" "rm" __git_alias "$git_blame_alias" "git" "blame" __git_alias "$git_diff_alias" "git" "diff" + __git_alias "$git_diff_word_alias" "git" "diff" "--word-diff" __git_alias "$git_diff_cached_alias" "git" "diff" "--cached" __git_alias "$git_add_patch_alias" "git" "add" "-p" # Custom default format for git log From fcf5dd3f6fcd30dde451aef855f7e37fd99216b0 Mon Sep 17 00:00:00 2001 From: Martin Grund Date: Tue, 8 Jan 2013 15:38:04 +0100 Subject: [PATCH 13/25] Fix for numbered directories or files This commit fixes some odd behavior for numbered files and directories. Even if the environment variables is undefined cd'ing into a numbered directory is not possible. This pathc fixes this by checking if the argument is a valid file or directory and is numnbered and if this is the case will only output the argument values instead of a substitution with $e.. In case there exist both, numbered valid argument and the directory or folder, the file will always win to avoid clashes with standard wrapped functions like cd, rm, mv... --- lib/git/status_shortcuts.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/git/status_shortcuts.sh b/lib/git/status_shortcuts.sh index 2b6bde6..32b643e 100644 --- a/lib/git/status_shortcuts.sh +++ b/lib/git/status_shortcuts.sh @@ -121,7 +121,11 @@ scmb_expand_args() { for arg in "$@"; do if [[ "$arg" =~ ^[0-9]+$ ]] ; then # Substitute $e{*} variables for any integers if [ "$first" -eq 1 ]; then first=0; else printf '\t'; fi - eval printf '%s' "\"\$$git_env_char$arg\"" + if [ -e "$arg" ]; then + printf '%s' "$arg" + else + eval printf '%s' "\"\$$git_env_char$arg\"" + fi elif [[ "$arg" =~ ^[0-9]+-[0-9]+$ ]]; then # Expand ranges into $e{*} variables for i in $(eval echo {${arg/-/..}}); do From 18e94797e9cb4d57855c1542e2d5efee68ae06bc Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Sat, 12 Jan 2013 12:16:55 +1300 Subject: [PATCH 14/25] Try removing quotes for array concatenation --- lib/git/repo_index.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/git/repo_index.sh b/lib/git/repo_index.sh index 0c0c181..57fa627 100644 --- a/lib/git/repo_index.sh +++ b/lib/git/repo_index.sh @@ -217,10 +217,10 @@ _git_index_update_all_branches() { # Ignore branch if remote and merge is not configured if [[ -n "$remote" ]] && [[ -n "$merge" ]]; then - branches=("${branches[@]}" "$branch") - remotes=("${remotes[@]}" "$remote") + branches=(${branches[@]} "$branch") + remotes=(${remotes[@]} "$remote") # Get branch from merge ref (refs/heads/master => master) - merges=("${merges[@]}" "$(basename $merge)") + merges=(${merges[@]} "$(basename $merge)") else echo "=== Skipping $branch: remote and merge refs are not configured." fi From 63f9fe00d7cbf2f350050ec9915720919c25bfc8 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Wed, 30 Jan 2013 10:25:13 +1300 Subject: [PATCH 15/25] Added gbD alias for 'git branch -D', and made gbd do a 'safe' delete with -d --- git.scmbrc.example | 1 + lib/git/branch_shortcuts.sh | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/git.scmbrc.example b/git.scmbrc.example index 7fce17c..f2b501b 100644 --- a/git.scmbrc.example +++ b/git.scmbrc.example @@ -72,6 +72,7 @@ git_branch_alias="gb" git_branch_all_alias="gba" git_branch_move_alias="gbm" git_branch_delete_alias="gbd" +git_branch_delete_force_alias="gbD" git_rebase_alias="grb" git_rebase_interactive_alias="grbi" git_rebase_alias_continue="grbc" diff --git a/lib/git/branch_shortcuts.sh b/lib/git/branch_shortcuts.sh index c57e646..25f2637 100644 --- a/lib/git/branch_shortcuts.sh +++ b/lib/git/branch_shortcuts.sh @@ -42,7 +42,8 @@ EOF alias "$git_branch_alias"="exec_scmb_expand_args _scmb_git_branch_shortcuts" alias "$git_branch_all_alias"="exec_scmb_expand_args _scmb_git_branch_shortcuts -a" alias "$git_branch_move_alias"="exec_scmb_expand_args _scmb_git_branch_shortcuts -m" -alias "$git_branch_delete_alias"="exec_scmb_expand_args _scmb_git_branch_shortcuts -D" +alias "$git_branch_delete_alias"="exec_scmb_expand_args _scmb_git_branch_shortcuts -d" +alias "$git_branch_delete_force_alias"="exec_scmb_expand_args _scmb_git_branch_shortcuts -D" # Define completions for git branch shortcuts if [ "$shell" = "bash" ]; then From d1a9df3844f761d8ba9a935e098349a18c73ace6 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Wed, 30 Jan 2013 11:05:50 +1300 Subject: [PATCH 16/25] Added keyboard shortcut to append [ ci skip ] to commit message when committing all files --- git.scmbrc.example | 5 +-- lib/git/keybindings.sh | 10 +++--- lib/git/status_shortcuts.sh | 8 +++-- test/lib/git/status_shortcuts_test.sh | 46 ++++++++++++++++++++++++--- 4 files changed, 56 insertions(+), 13 deletions(-) diff --git a/git.scmbrc.example b/git.scmbrc.example index f2b501b..2191309 100644 --- a/git.scmbrc.example +++ b/git.scmbrc.example @@ -91,8 +91,9 @@ git_tag_alias="gt" # ---------------------------------------------- # Keyboard shortcuts are on by default. Set this to 'false' to disable them. git_keyboard_shortcuts_enabled="true" -git_commit_all_keys="\C-x " # CTRL+x, SPACE -git_add_and_commit_keys="\C-xc" # CTRL+x, c +git_commit_all_keys="\C-x " # CTRL+x, SPACE +git_add_and_commit_keys="\C-xc" # CTRL+x, c +git_commit_all_with_ci_skip_keys="\C-xv" # CTRL+x, v (Appends [ci skip] to commit message) # Shell Command Wrapping diff --git a/lib/git/keybindings.sh b/lib/git/keybindings.sh index d077353..4ea46c3 100644 --- a/lib/git/keybindings.sh +++ b/lib/git/keybindings.sh @@ -27,11 +27,13 @@ if [[ "$git_keyboard_shortcuts_enabled" = "true" ]]; then # Uses emacs style keybindings, so vi mode is not supported for now if ! set -o | grep -q '^vi .*on$'; then if [[ $shell == "zsh" ]]; then - _bind "$git_commit_all_keys" " git_commit_all""\n" - _bind "$git_add_and_commit_keys" " \033[1~ git_add_and_commit ""\n" + _bind "$git_commit_all_keys" " git_commit_all""\n" + _bind "$git_add_and_commit_keys" " \033[1~ git_add_and_commit ""\n" + _bind "$git_commit_all_with_ci_skip_keys" " \033[1~ APPEND='[ci skip]' git_commit_all ""\n" else - _bind "$git_commit_all_keys" "\" git_commit_all\n\"" - _bind "$git_add_and_commit_keys" "\"\033[1~ git_add_and_commit \n\"" + _bind "$git_commit_all_keys" "\" git_commit_all\n\"" + _bind "$git_add_and_commit_keys" "\"\033[1~ git_add_and_commit \n\"" + _bind "$git_commit_all_with_ci_skip_keys" "\"\033[1~ APPEND='[ci skip]' git_commit_all \n\"" fi fi diff --git a/lib/git/status_shortcuts.sh b/lib/git/status_shortcuts.sh index 32b643e..c03485d 100644 --- a/lib/git/status_shortcuts.sh +++ b/lib/git/status_shortcuts.sh @@ -189,6 +189,8 @@ git_commit_prompt() { if [ -n "$commit_msg" ]; then eval $@ # run any prequisite commands + # Add $APPEND to commit message, if given. (Used to append things like [ci skip] for Travis CI) + if [ -n "$APPEND" ]; then commit_msg="$commit_msg $APPEND"; fi echo $commit_msg | git commit -F - | tail -n +2 else echo -e "\033[0;31mAborting commit due to empty commit message.\033[0m" @@ -210,7 +212,10 @@ git_commit_all() { fail_if_not_git_repo || return 1 changes=$(git status --porcelain | wc -l) if [ "$changes" -gt 0 ]; then - echo -e "\033[0;33mCommitting all files (\033[0;31m$changes\033[0;33m)\033[0m" + if [ -n "$APPEND" ]; then + local appending=" | \033[0;36mappending '\033[1;36m$APPEND\033[0;36m' to commit message.\033[0m" + fi + echo -e "\033[0;33mCommitting all files (\033[0;31m$changes\033[0;33m)\033[0m$appending" git_commit_prompt "git add -A" else echo "# No changed files to commit." @@ -229,4 +234,3 @@ git_add_and_commit() { echo "# No staged changes to commit." fi } - diff --git a/test/lib/git/status_shortcuts_test.sh b/test/lib/git/status_shortcuts_test.sh index 626873d..aa86d2e 100755 --- a/test/lib/git/status_shortcuts_test.sh +++ b/test/lib/git/status_shortcuts_test.sh @@ -234,9 +234,9 @@ test_git_commit_prompt() { commit_msg="\"Nathan's git commit prompt function!\"" dbl_escaped_msg="\\\\\"Nathan's git commit prompt function\"'"'!'"'\"\\\\\"" # Create temporary history file - HISTFILE=$(mktemp -t scm_breeze.XXXXXXXXXX) - HISTFILESIZE=1000 - HISTSIZE=1000 + export HISTFILE=$(mktemp -t scm_breeze.XXXXXXXXXX) + export HISTFILESIZE=1000 + export HISTSIZE=1000 touch a b c d git add . > /dev/null @@ -252,12 +252,48 @@ test_git_commit_prompt() { assertIncludes "$git_show_output" "$commit_msg" # Test that history was appended correctly. - if [[ $shell != "zsh" ]]; then history -n; fi # Reload bash history - test_history="$(history)" + if [[ $shell == "zsh" ]]; then + test_history="$(history)" + else + test_history="$(cat $HISTFILE)" + fi assertIncludes "$test_history" "$commit_msg" assertIncludes "$test_history" "git commit -m \"$dbl_escaped_msg\"" } +test_git_commit_prompt_with_append() { + setupTestRepo + + commit_msg="Updating README, no build please" + + # Create temporary history file + HISTFILE=$(mktemp -t scm_breeze.XXXXXXXXXX) + HISTFILESIZE=1000 + HISTSIZE=1000 + + touch a b c + git add . > /dev/null + + # Zsh 'vared' doesn't handle input via pipe, so replace with function that reads into commit_msg variable. + function vared(){ read commit_msg; } + + # Test the git commit prompt, by piping a commit message + # instead of user input. + echo "$commit_msg" | APPEND="[ci skip]" git_commit_prompt > /dev/null + + git_show_output=$(git show --oneline --name-only) + assertIncludes "$git_show_output" "$commit_msg \[ci skip\]" + + # Test that history was appended correctly. + if [[ $shell == "zsh" ]]; then + test_history="$(history)" + else + test_history="$(cat $HISTFILE)" + fi + assertIncludes "$test_history" "$commit_msg \[ci skip\]" + assertIncludes "$test_history" "git commit -m \"$commit_msg \[ci skip\]\"" +} + test_adding_files_with_spaces() { setupTestRepo From 5b7a2c43070c704379b620575779caad59c931e6 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Wed, 30 Jan 2013 12:05:40 +1300 Subject: [PATCH 17/25] Ensure SCM Breeze is loaded after RVM when wrapping the cd command --- lib/git/shell_shortcuts.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/git/shell_shortcuts.sh b/lib/git/shell_shortcuts.sh index f7ed845..8026f0b 100644 --- a/lib/git/shell_shortcuts.sh +++ b/lib/git/shell_shortcuts.sh @@ -16,6 +16,15 @@ if [ "$shell_command_wrapping_enabled" = "true" ] || [ "$bash_command_wrapping_e for cmd in $(echo $scmb_wrapped_shell_commands); do if [ "${scmbDebug:-}" = "true" ]; then echo "SCMB: Wrapping $cmd..."; fi + # Special check for 'cd', to make sure SCM Breeze is loaded after RVM + if [ "$cmd" = 'cd' ]; then + if [ -e "$HOME/.rvm" ] && ! type rvm > /dev/null 2>&1; then + echo -e "\033[0;31mSCM Breeze must be loaded \033[1;31mafter\033[0;31m RVM, otherwise there will be a conflict when RVM wraps the 'cd' command.\033[0m" + echo -e "\033[0;31mPlease move the line that loads SCM Breeze to the bottom of your ~/.bashrc\033[0m" + continue + fi + fi + case "$(type $cmd 2>&1)" in # Don't do anything if command already aliased, or not found. From 3692db6a3ad1a607c170f26a8697dc275784ecca Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Wed, 30 Jan 2013 12:09:44 +1300 Subject: [PATCH 18/25] Ensure tests run if RVM isn't loaded but $HOME/.rvm is present --- test/lib/git/shell_shortcuts_test.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/lib/git/shell_shortcuts_test.sh b/test/lib/git/shell_shortcuts_test.sh index f1863e7..fe17eb9 100755 --- a/test/lib/git/shell_shortcuts_test.sh +++ b/test/lib/git/shell_shortcuts_test.sh @@ -27,6 +27,8 @@ oneTimeSetUp() { export shell_command_wrapping_enabled="true" export scmb_wrapped_shell_commands="not_found cat rm cp mv ln cd sed" + alias rvm="test" # Ensure tests run if RVM isn't loaded but $HOME/.rvm is present + # Test functions function ln() { ln $@; } # Test aliases From dd10be79e28564b84d0fef0598437baafc79677a Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Wed, 30 Jan 2013 22:29:05 +1300 Subject: [PATCH 19/25] Re-wrap functions as functions. Fixes issue with RVM reload (cd wrapper will be overwritten without error) --- lib/git/shell_shortcuts.sh | 4 ++-- test/lib/git/shell_shortcuts_test.sh | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/git/shell_shortcuts.sh b/lib/git/shell_shortcuts.sh index 8026f0b..690bf93 100644 --- a/lib/git/shell_shortcuts.sh +++ b/lib/git/shell_shortcuts.sh @@ -60,8 +60,8 @@ if [ "$shell_command_wrapping_enabled" = "true" ] || [ "$bash_command_wrapping_e eval "$(declare -f $cmd | sed -E "s/^$cmd \(\)/__original_$cmd ()/")" # Remove function unset -f $cmd - # Create wrapped alias for old function - alias "$cmd"="exec_scmb_expand_args __original_$cmd";; + # Create function that wraps old function + eval "${cmd}(){ exec_scmb_expand_args __original_${cmd} \"\$@\"; }";; *'is a shell builtin'*) if [ "${scmbDebug:-}" = "true" ]; then echo "SCMB: $cmd is a shell builtin"; fi diff --git a/test/lib/git/shell_shortcuts_test.sh b/test/lib/git/shell_shortcuts_test.sh index fe17eb9..3a6843a 100755 --- a/test/lib/git/shell_shortcuts_test.sh +++ b/test/lib/git/shell_shortcuts_test.sh @@ -63,7 +63,8 @@ test_shell_command_wrapping() { assertAliasEquals "exec_scmb_expand_args /bin/sed" "sed" assertAliasEquals "exec_scmb_expand_args /bin/cat" "cat" assertAliasEquals "exec_scmb_expand_args builtin cd" "cd" - assertAliasEquals "exec_scmb_expand_args __original_ln" "ln" + assertIncludes "$(declare -f ln)" "ln ()" + assertIncludes "$(declare -f ln)" "exec_scmb_expand_args __original_ln" } test_ls_with_file_shortcuts() { From adedf869711923b99e2ce984368235ea2139464c Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Sun, 3 Feb 2013 13:35:59 +1300 Subject: [PATCH 20/25] No expand args for git reset --- lib/git/aliases.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/git/aliases.sh b/lib/git/aliases.sh index 8791bd9..8c715a1 100644 --- a/lib/git/aliases.sh +++ b/lib/git/aliases.sh @@ -26,7 +26,7 @@ if type hub > /dev/null 2>&1; then export _git_cmd="hub"; fi function git(){ # Only expand args for git commands that deal with paths or branches case $1 in - checkout|commit|reset|rm|blame|diff|add|log|rebase) + checkout|commit|rm|blame|diff|add|log|rebase) exec_scmb_expand_args "$_git_cmd" "$@";; branch) _scmb_git_branch_shortcuts "${@:2}";; From d9351f82c4de94bcc5da28d5a97add9b4803d404 Mon Sep 17 00:00:00 2001 From: Giuseppe Rota Date: Tue, 12 Mar 2013 22:35:42 +0100 Subject: [PATCH 21/25] Conditional git branch aliases definition --- lib/git/branch_shortcuts.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/git/branch_shortcuts.sh b/lib/git/branch_shortcuts.sh index 25f2637..e7b9064 100644 --- a/lib/git/branch_shortcuts.sh +++ b/lib/git/branch_shortcuts.sh @@ -39,11 +39,11 @@ EOF done } -alias "$git_branch_alias"="exec_scmb_expand_args _scmb_git_branch_shortcuts" -alias "$git_branch_all_alias"="exec_scmb_expand_args _scmb_git_branch_shortcuts -a" -alias "$git_branch_move_alias"="exec_scmb_expand_args _scmb_git_branch_shortcuts -m" -alias "$git_branch_delete_alias"="exec_scmb_expand_args _scmb_git_branch_shortcuts -d" -alias "$git_branch_delete_force_alias"="exec_scmb_expand_args _scmb_git_branch_shortcuts -D" +__git_alias "$git_branch_alias" "_scmb_git_branch_shortcuts" +__git_alias "$git_branch_all_alias" "_scmb_git_branch_shortcuts" "-a" +__git_alias "$git_branch_move_alias" "_scmb_git_branch_shortcuts" "-m" +__git_alias "$git_branch_delete_alias" "_scmb_git_branch_shortcuts" "-d" +__git_alias "$git_branch_delete_force_alias" "_scmb_git_branch_shortcuts" "-D" # Define completions for git branch shortcuts if [ "$shell" = "bash" ]; then @@ -51,4 +51,4 @@ if [ "$shell" = "bash" ]; then __define_git_completion $alias_str branch complete -o default -o nospace -F _git_"$alias_str"_shortcut $alias_str done -fi \ No newline at end of file +fi From 7ffbaefb036b95a1175c7404eb630c2ec6134648 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Tue, 9 Apr 2013 12:03:43 +1200 Subject: [PATCH 22/25] Set up demo git user for tests --- test/support/test_helper.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/support/test_helper.sh b/test/support/test_helper.sh index bf371d0..9838938 100644 --- a/test/support/test_helper.sh +++ b/test/support/test_helper.sh @@ -3,6 +3,13 @@ orig_cwd="$PWD" # Load SCM Breeze helpers source "$scmbDir/lib/git/helpers.sh" +if [ -z "$(git config --global user.email)" ]; then + git config --global user.email "testuser@example.com" +fi +if [ -z "$(git config --global user.name)" ]; then + git config --global user.name "Test User" +fi + # # Test helpers #----------------------------------------------------------------------------- From fc9d7787b197f12685d4b9da0cb453dd5797ddd4 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Tue, 9 Apr 2013 12:04:45 +1200 Subject: [PATCH 23/25] Updated demo user setup --- test/support/test_helper.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/support/test_helper.sh b/test/support/test_helper.sh index 9838938..7407b59 100644 --- a/test/support/test_helper.sh +++ b/test/support/test_helper.sh @@ -3,11 +3,10 @@ orig_cwd="$PWD" # Load SCM Breeze helpers source "$scmbDir/lib/git/helpers.sh" +# Set up demo git user if not configured if [ -z "$(git config --global user.email)" ]; then git config --global user.email "testuser@example.com" -fi -if [ -z "$(git config --global user.name)" ]; then - git config --global user.name "Test User" + git config --global user.name "Test User" fi # From a8b1284244f948dd7c9bc4fc0b3578904b2c4470 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Tue, 9 Apr 2013 12:09:59 +1200 Subject: [PATCH 24/25] Updated readme [ci skip] --- README.markdown | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.markdown b/README.markdown index ff430f4..329d87e 100644 --- a/README.markdown +++ b/README.markdown @@ -1,12 +1,9 @@ # SCM Breeze [![TravisCI](https://secure.travis-ci.org/ndbroadbent/scm_breeze.png?branch=master)](http://travis-ci.org/ndbroadbent/scm_breeze) ### Streamline your SCM workflow. -**SCM Breeze** is a set of shell scripts (for `bash` and `zsh`) that enhance your interaction with tools -such as git. It integrates with your shell to give you numbered file shortcuts, +**SCM Breeze** is a set of shell scripts (for `bash` and `zsh`) that enhance your interaction with git. It integrates with your shell to give you numbered file shortcuts, a repository index with tab completion, and many other useful features. -Note: **git** is currently the only supported SCM. I've kept the project's name generic, but other SCMs aren't supported yet. -
## Demo video @@ -29,7 +26,7 @@ You can configure the variable prefix, which is 'e' by default.
-### UPDATE: Now with 'ls' shortcuts: +### 'ls' shortcuts:
Ls With Shortcuts From 6fec96ee353420c3116a5a29e92f0717216af5be Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Tue, 9 Apr 2013 12:13:50 +1200 Subject: [PATCH 25/25] Update README [ci skip] --- README.markdown | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/README.markdown b/README.markdown index 329d87e..88b9695 100644 --- a/README.markdown +++ b/README.markdown @@ -283,6 +283,12 @@ The install script just adds the following line to your `.bashrc` or `.zshrc`: `[ -s "$HOME/.scm_breeze/scm_breeze.sh" ] && source "$HOME/.scm_breeze/scm_breeze.sh"` + +# Updating + +Please run `update_scm_breeze` to fetch the latest code. This will update SCM Breeze from Github, +and will create or patch your `~/.*.scmbrc` config files if any new settings are added. + # Uninstall ```bash @@ -335,13 +341,6 @@ You will need to set that up yourself. You just need to set the option: `setopt no_complete_aliases` (oh-my-zsh sets this by default). Zsh will then expand aliases like `gb` to `git branch`, and use the completion for that. - -# Updating - -Run `update_scm_breeze`. This will update SCM Breeze from Github, -and will create or patch your `~/.*.scmbrc` files if any new settings are added. - - # Contributing SCM Breeze lives on Github at [https://github.com/ndbroadbent/scm_breeze](https://github.com/ndbroadbent/scm_breeze)