Merge remote-tracking branch 'origin/master' into refactor_of_git_status
This commit is contained in:
@@ -21,12 +21,14 @@ export _git_cmd="$(\which git)"
|
||||
# Wrap git with the 'hub' github wrapper, if installed (https://github.com/defunkt/hub)
|
||||
if type hub > /dev/null 2>&1; then export _git_cmd="hub"; fi
|
||||
|
||||
# gh is now deprecated, and merged into the `hub` command line tool.
|
||||
#if type gh > /dev/null 2>&1; then export _git_cmd="gh"; fi
|
||||
|
||||
# Create 'git' function that calls hub if defined, and expands all numeric arguments
|
||||
function git(){
|
||||
# Only expand args for git commands that deal with paths or branches
|
||||
case $1 in
|
||||
commit|blame|add|log|rebase|merge)
|
||||
commit|blame|add|log|rebase|merge|difftool)
|
||||
exec_scmb_expand_args "$_git_cmd" "$@";;
|
||||
checkout|diff|rm|reset)
|
||||
exec_scmb_expand_args --relative "$_git_cmd" "$@";;
|
||||
@@ -37,7 +39,7 @@ function git(){
|
||||
esac
|
||||
}
|
||||
|
||||
_alias $git_alias='git'
|
||||
_alias "$git_alias" "git"
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
@@ -64,91 +66,111 @@ _git
|
||||
# Usage: __git_alias <alias> <command_prefix> <command>
|
||||
__git_alias () {
|
||||
if [ -n "$1" ]; then
|
||||
local alias_str="$1"; local cmd_prefix="$2"; local cmd="$3"; local cmd_args="${4-}"
|
||||
alias $alias_str="$cmd_prefix $cmd${cmd_args:+ }$cmd_args"
|
||||
local alias_str cmd_prefix cmd cmd_args
|
||||
|
||||
alias_str="$1"; cmd_prefix="$2"; cmd="$3";
|
||||
if [ $# -gt 2 ]; then
|
||||
shift 3 2>/dev/null
|
||||
cmd_args=$@
|
||||
fi
|
||||
|
||||
alias $alias_str="$cmd_prefix $cmd${cmd_args:+ }${cmd_args[*]}"
|
||||
if [ "$shell" = "bash" ]; then
|
||||
__define_git_completion $alias_str $cmd
|
||||
complete -o default -o nospace -F _git_"$alias_str"_shortcut $alias_str
|
||||
__define_git_completion "$alias_str" "$cmd"
|
||||
complete -o default -o nospace -F _git_"$alias_str"_shortcut "$alias_str"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# SCM Breeze functions
|
||||
_alias $git_status_shortcuts_alias="git_status_shortcuts"
|
||||
_alias $git_add_shortcuts_alias="git_add_shortcuts"
|
||||
_alias $exec_scmb_expand_args_alias="exec_scmb_expand_args"
|
||||
_alias $git_show_files_alias="git_show_affected_files"
|
||||
_alias $git_commit_all_alias='git_commit_all'
|
||||
_alias "$git_status_shortcuts_alias" 'git_status_shortcuts'
|
||||
_alias "$git_add_shortcuts_alias" 'git_add_shortcuts'
|
||||
_alias "$exec_scmb_expand_args_alias" 'exec_scmb_expand_args'
|
||||
_alias "$git_show_files_alias" 'git_show_affected_files'
|
||||
_alias "$git_commit_all_alias" 'git_commit_all'
|
||||
_alias "$git_grep_shortcuts_alias" 'git_grep_shortcuts'
|
||||
|
||||
# Git Index alias
|
||||
_alias $git_index_alias="git_index"
|
||||
_alias "$git_index_alias" 'git_index'
|
||||
|
||||
# Only set up the following aliases if 'git_setup_aliases' is 'yes'
|
||||
if [ "$git_setup_aliases" = "yes" ]; then
|
||||
|
||||
# Commands that deal with paths
|
||||
__git_alias "$git_checkout_alias" "git" "checkout"
|
||||
__git_alias "$git_commit_alias" "git" "commit"
|
||||
__git_alias "$git_commit_verbose_alias" "git" "commit" "--verbose"
|
||||
__git_alias "$git_reset_alias" "git" "reset" "--"
|
||||
__git_alias "$git_reset_hard_alias" "git" "reset" "--hard"
|
||||
__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"
|
||||
__git_alias "$git_add_updated_alias" "git" "add" "-u"
|
||||
__git_alias "$git_difftool_alias" "git" "difftool"
|
||||
__git_alias "$git_checkout_alias" 'git' 'checkout'
|
||||
__git_alias "$git_commit_alias" 'git' 'commit'
|
||||
__git_alias "$git_commit_verbose_alias" 'git' 'commit' '--verbose'
|
||||
__git_alias "$git_reset_alias" 'git' 'reset'
|
||||
__git_alias "$git_reset_hard_alias" 'git' 'reset' '--hard'
|
||||
__git_alias "$git_rm_alias" 'git' 'rm'
|
||||
__git_alias "$git_blame_alias" 'git' 'blame'
|
||||
__git_alias "$git_diff_no_whitespace_alias" 'git' 'diff' '-w'
|
||||
__git_alias "$git_diff_alias" 'git' 'diff'
|
||||
__git_alias "$git_diff_file_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'
|
||||
__git_alias "$git_add_updated_alias" 'git' 'add' '-u'
|
||||
__git_alias "$git_difftool_alias" 'git' 'difftool'
|
||||
|
||||
# Custom default format for git log
|
||||
git_log_command="log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
|
||||
__git_alias "$git_log_alias" "git" "$git_log_command"
|
||||
__git_alias "$git_log_alias" 'git' "$git_log_command"
|
||||
|
||||
# Same as the above, but displays all the branches and remotes
|
||||
__git_alias "$git_log_all_alias" "git" "$git_log_command" "--branches" "--remotes"
|
||||
__git_alias "$git_log_all_alias" 'git' "$git_log_command" '--branches' '--remotes'
|
||||
|
||||
# Standard commands
|
||||
__git_alias "$git_clone_alias" "git" 'clone'
|
||||
__git_alias "$git_fetch_alias" "git" 'fetch'
|
||||
__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"
|
||||
__git_alias "$git_clean_force_alias" "git" "clean" "-fd"
|
||||
__git_alias "$git_remote_alias" "git" 'remote' '-v'
|
||||
__git_alias "$git_rebase_alias" "git" 'rebase'
|
||||
__git_alias "$git_rebase_interactive_alias" "git" 'rebase' "-i"
|
||||
__git_alias "$git_rebase_alias_continue" "git" 'rebase' "--continue"
|
||||
__git_alias "$git_rebase_alias_abort" "git" 'rebase' "--abort"
|
||||
__git_alias "$git_reset_last_commit" "git" "reset HEAD~"
|
||||
__git_alias "$git_merge_alias" "git" 'merge'
|
||||
__git_alias "$git_merge_no_fast_forward_alias" "git" "merge" "--no-ff"
|
||||
__git_alias "$git_merge_only_fast_forward_alias" "git" "merge" "--ff"
|
||||
__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_stash_alias" "git" 'stash'
|
||||
__git_alias "$git_stash_apply_alias" "git" 'stash' 'apply'
|
||||
__git_alias "$git_stash_pop_alias" "git" 'stash' 'pop'
|
||||
__git_alias "$git_stash_list_alias" "git" 'stash' 'list'
|
||||
__git_alias "$git_tag_alias" "git" 'tag'
|
||||
|
||||
__git_alias "$git_clone_alias" 'git' 'clone'
|
||||
__git_alias "$git_fetch_alias" 'git' 'fetch'
|
||||
__git_alias "$git_checkout_branch_alias" 'git' 'checkout' '-b'
|
||||
__git_alias "$git_pull_alias" 'git' 'pull'
|
||||
__git_alias "$git_pull_rebase_alias" 'git' 'pull' '--rebase'
|
||||
__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'
|
||||
__git_alias "$git_clean_force_alias" 'git' 'clean' '-fd'
|
||||
__git_alias "$git_remote_alias" 'git' 'remote' '-v'
|
||||
__git_alias "$git_rebase_alias" 'git' 'rebase'
|
||||
__git_alias "$git_rebase_interactive_alias" 'git' 'rebase' '-i'
|
||||
__git_alias "$git_rebase_alias_continue" 'git' 'rebase' '--continue'
|
||||
__git_alias "$git_rebase_alias_abort" 'git' 'rebase' '--abort'
|
||||
__git_alias "$git_reset_last_commit" 'git' 'reset HEAD~'
|
||||
__git_alias "$git_top_level_alias" 'git' 'rev-parse' '--show-toplevel'
|
||||
__git_alias "$git_merge_alias" 'git' 'merge'
|
||||
__git_alias "$git_merge_no_fast_forward_alias" 'git' 'merge' '--no-ff'
|
||||
__git_alias "$git_merge_only_fast_forward_alias" 'git' 'merge' '--ff'
|
||||
__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_stash_alias" 'git' 'stash'
|
||||
__git_alias "$git_stash_apply_alias" 'git' 'stash' 'apply'
|
||||
__git_alias "$git_stash_pop_alias" 'git' 'stash' 'pop'
|
||||
__git_alias "$git_stash_list_alias" 'git' 'stash' 'list'
|
||||
__git_alias "$git_tag_alias" 'git' 'tag'
|
||||
__git_alias "$git_submodule_update_alias" 'git' 'submodule' 'update' '--init'
|
||||
__git_alias "$git_submodule_update_rec_alias" 'git' 'submodule' 'update' '--init' '--recursive'
|
||||
__git_alias "$git_whatchanged_alias" 'git' 'whatchanged'
|
||||
__git_alias "$git_apply_alias" 'git' 'apply'
|
||||
|
||||
# Compound/complex commands
|
||||
_alias $git_fetch_all_alias="git fetch --all"
|
||||
_alias $git_pull_then_push_alias="git pull && git push"
|
||||
_alias $git_fetch_and_rebase_alias='git fetch && git rebase'
|
||||
_alias $git_commit_amend_alias='git commit --amend'
|
||||
_alias "$git_fetch_all_alias" 'git fetch --all'
|
||||
_alias "$git_pull_then_push_alias" 'git pull && git push'
|
||||
_alias "$git_fetch_and_rebase_alias" 'git fetch && git rebase'
|
||||
_alias "$git_commit_amend_alias" 'git commit --amend'
|
||||
|
||||
# Add staged changes to latest commit without prompting for message
|
||||
_alias $git_commit_amend_no_msg_alias='git commit --amend -C HEAD'
|
||||
_alias $git_commit_no_msg_alias='git commit -C HEAD'
|
||||
_alias $git_log_stat_alias='git log --stat --max-count=5'
|
||||
_alias $git_log_graph_alias='git log --graph --max-count=5'
|
||||
_alias $git_add_all_alias='git add -A'
|
||||
_alias "$git_commit_amend_no_msg_alias" 'git commit --amend -C HEAD'
|
||||
_alias "$git_commit_no_msg_alias" 'git commit -C HEAD'
|
||||
_alias "$git_log_stat_alias" 'git log --stat --max-count=5'
|
||||
_alias "$git_log_graph_alias" 'git log --graph --max-count=5'
|
||||
_alias "$git_add_all_alias" 'git add --all .'
|
||||
|
||||
# Hub aliases (https://github.com/github/hub)
|
||||
_alias "$git_pull_request_alias" 'git pull-request'
|
||||
fi
|
||||
|
||||
|
||||
@@ -168,4 +190,3 @@ if [ $shell = "bash" ]; then
|
||||
else
|
||||
compdef _git_index_tab_completion git_index $git_index_alias
|
||||
fi
|
||||
|
||||
|
||||
@@ -13,8 +13,9 @@
|
||||
unalias $git_branch_alias > /dev/null 2>&1; unset -f $git_branch_alias > /dev/null 2>&1
|
||||
function _scmb_git_branch_shortcuts {
|
||||
fail_if_not_git_repo || return 1
|
||||
|
||||
# Fall back to normal git branch, if any unknown args given
|
||||
if [[ -n "$@" ]] && [[ "$@" != "-a" ]]; then
|
||||
if [[ "$($_git_cmd branch | wc -l)" -gt 300 ]] || ([[ -n "$@" ]] && [[ "$@" != "-a" ]]); then
|
||||
exec_scmb_expand_args $_git_cmd branch "$@"
|
||||
return 1
|
||||
fi
|
||||
@@ -32,14 +33,16 @@ EOF
|
||||
|
||||
# Set numbered file shortcut in variable
|
||||
local e=1
|
||||
IFS=$'\n'
|
||||
for branch in $($_git_cmd branch "$@" | sed "s/^[* ]\{2\}//"); do
|
||||
export $git_env_char$e="$branch"
|
||||
if [ "${scmbDebug:-}" = "true" ]; then echo "Set \$$git_env_char$e => $file"; fi
|
||||
let e++
|
||||
done
|
||||
unset IFS
|
||||
}
|
||||
|
||||
__git_alias "$git_branch_alias" "_scmb_git_branch_shortcuts"
|
||||
__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"
|
||||
|
||||
4
lib/git/fallback/status_shortcuts_shell.sh
Normal file → Executable file
4
lib/git/fallback/status_shortcuts_shell.sh
Normal file → Executable file
@@ -114,7 +114,7 @@ git_status_shortcuts() {
|
||||
# so just use plain 'git status'
|
||||
git status
|
||||
fi
|
||||
IFS=$' \t\n'
|
||||
unset IFS
|
||||
zsh_reset # Reset zsh environment to default
|
||||
}
|
||||
# Template function for 'git_status_shortcuts'.
|
||||
@@ -127,7 +127,7 @@ _gs_output_file_group() {
|
||||
if [ -z "$project_root" ]; then
|
||||
relative="${stat_file[$i]}"
|
||||
else
|
||||
dest="$project_root/${stat_file[$i]}"
|
||||
dest=$(readlink -f "$project_root/${stat_file[$i]}")
|
||||
local pwd=$(readlink -f "$PWD")
|
||||
relative="$(_gs_relative_path "$pwd" "$dest" )"
|
||||
fi
|
||||
|
||||
47
lib/git/grep_shortcuts.rb
Normal file
47
lib/git/grep_shortcuts.rb
Normal file
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env ruby
|
||||
# encoding: UTF-8
|
||||
|
||||
PROJECT_ROOT = File.exist?(".git") ? Dir.pwd : `\git rev-parse --show-toplevel 2> /dev/null`.strip
|
||||
|
||||
COLORS = {
|
||||
:rst => "\033[0m",
|
||||
:del => "\033[0;31m",
|
||||
:mod => "\033[0;32m",
|
||||
:new => "\033[0;33m",
|
||||
:ren => "\033[0;34m",
|
||||
:cpy => "\033[0;33m",
|
||||
:typ => "\033[0;35m",
|
||||
:unt => "\033[0;36m",
|
||||
:dark => "\033[2;37m",
|
||||
:branch => "\033[1m",
|
||||
:header => "\033[0m"
|
||||
}
|
||||
|
||||
COLOR_MATCH = /\e\[[0-9;]*[mK]/
|
||||
|
||||
output_files = []
|
||||
|
||||
stdin = STDIN.set_encoding(Encoding::ASCII_8BIT)
|
||||
|
||||
while stdin.gets
|
||||
if $. > 1000
|
||||
puts "Only showing first 1000 results. Please refine your search."
|
||||
break
|
||||
end
|
||||
print "#{COLORS[:dark]}[#{COLORS[:rst]}#{$.}#{COLORS[:dark]}]#{COLORS[:rst]} "
|
||||
matches = $_.match(/(^.+?)#{COLOR_MATCH}?:#{COLOR_MATCH}?(\d+)?/)
|
||||
file = matches[1]
|
||||
line = matches[2]
|
||||
output_files << "#{file}#{line ? ":#{line}" : ""}"
|
||||
puts $_
|
||||
end
|
||||
|
||||
print "@@filelist@@::"
|
||||
|
||||
output_files.each_with_index {|f,i|
|
||||
# If file starts with a '~', treat it as a relative path.
|
||||
# This is important when dealing with symlinks
|
||||
print "|" unless i == 0
|
||||
print f.start_with?("~") ? f.sub(/~/, '') : File.join(PROJECT_ROOT, f)
|
||||
}
|
||||
puts
|
||||
24
lib/git/grep_shortcuts.sh
Normal file
24
lib/git/grep_shortcuts.sh
Normal file
@@ -0,0 +1,24 @@
|
||||
git_grep_shortcuts() {
|
||||
fail_if_not_git_repo || return 1
|
||||
git_clear_vars
|
||||
# Run ruby script, store output
|
||||
tmp_grep_results="$(git rev-parse --git-dir)/tmp_grep_results_$$"
|
||||
git grep -n --color=always "$@" |
|
||||
/usr/bin/env ruby "$scmbDir/lib/git/grep_shortcuts.rb" >"$tmp_grep_results"
|
||||
|
||||
# Fetch list of files from last line of script output
|
||||
files="$(tail -1 "$tmp_grep_results" | sed 's%@@filelist@@::%%g')"
|
||||
|
||||
# Export numbered env variables for each file
|
||||
IFS="|"
|
||||
local e=1
|
||||
for file in ${=files}; do
|
||||
export $git_env_char$e="$file"
|
||||
let e++
|
||||
done
|
||||
IFS=$' \t\n'
|
||||
|
||||
# Print status
|
||||
cat "$tmp_grep_results" | sed '$d' | less -SfRMXFi
|
||||
rm -f "$tmp_grep_results"
|
||||
}
|
||||
@@ -27,13 +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_with_ci_skip_keys" " \033[1~ APPEND='[ci skip]' git_commit_all ""\n"
|
||||
_bind "$git_commit_all_keys" " git_commit_all""^M"
|
||||
_bind "$git_add_and_commit_keys" " \033[1~ git_add_and_commit ""^M"
|
||||
_bind "$git_commit_all_with_ci_skip_keys" " \033[1~ APPEND='[ci skip]' git_commit_all ""^M"
|
||||
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_with_ci_skip_keys" "\"\033[1~ APPEND='[ci skip]' git_commit_all \n\""
|
||||
_bind "$git_commit_all_keys" "\" git_commit_all^M\""
|
||||
_bind "$git_add_and_commit_keys" "\"\C-A git_add_and_commit ^M\""
|
||||
_bind "$git_commit_all_with_ci_skip_keys" "\"\C-A APPEND='[ci skip]' git_commit_all ^M\""
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
@@ -68,8 +68,8 @@ function git_index() {
|
||||
elif [ "$1" = "--list" ] || [ "$1" = "-l" ]; then
|
||||
echo -e "$_bld_col$(_git_index_count)$_txt_col Git repositories in $_bld_col$GIT_REPO_DIR$_txt_col:\n"
|
||||
for repo in $(_git_index_dirs_without_home); do
|
||||
echo $(basename $repo) : $repo
|
||||
done | sort | column -t -s ':'
|
||||
echo $(basename $repo | sed "s/ /_/g") : $repo
|
||||
done | sort -t ":" -k1,1 | column -t -s ':'
|
||||
elif [ "$1" = "--count-by-host" ]; then
|
||||
echo -e "=== Producing a report of the number of repos per host...\n"
|
||||
_git_index_batch_cmd git remote -v | \grep "origin.*(fetch)" |
|
||||
@@ -116,7 +116,7 @@ function git_index() {
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
IFS=$' \t\n'
|
||||
unset IFS
|
||||
}
|
||||
|
||||
_git_index_dirs_without_home() {
|
||||
@@ -127,11 +127,11 @@ _git_index_dirs_without_home() {
|
||||
function _find_git_repos() {
|
||||
# Find all unarchived projects
|
||||
IFS=$'\n'
|
||||
for repo in $(find -L "$GIT_REPO_DIR" -maxdepth 4 -name ".git" -type d \! -wholename '*/archive/*'); do
|
||||
for repo in $(find -L "$GIT_REPO_DIR" -maxdepth 5 -name ".git" -type d \! -wholename '*/archive/*'); do
|
||||
echo ${repo%/.git} # Return project folder, with trailing ':'
|
||||
_find_git_submodules $repo # Detect any submodules
|
||||
done
|
||||
IFS=$' \t\n'
|
||||
unset IFS
|
||||
}
|
||||
|
||||
# List all submodules for a git repo, if any.
|
||||
@@ -148,9 +148,9 @@ function _rebuild_git_index() {
|
||||
# Get repos from src dir and custom dirs, then sort by basename
|
||||
IFS=$'\n'
|
||||
for repo in $(echo -e "$(_find_git_repos)\n$(echo $GIT_REPOS | sed "s/:/\\\\n/g")"); do
|
||||
echo $(basename $repo | sed "s/ /_/g") $repo
|
||||
done | sort | cut -d " " -f2- > "$GIT_REPO_DIR/.git_index"
|
||||
IFS=$' \t\n'
|
||||
echo $(basename $repo | sed "s/ /_/g"):$repo
|
||||
done | sort -t ":" -k1,1 | cut -d ":" -f2- >| "$GIT_REPO_DIR/.git_index"
|
||||
unset IFS
|
||||
|
||||
if [ "$1" != "--silent" ]; then
|
||||
echo -e "===== Indexed $_bld_col$(_git_index_count)$_txt_col repos in $GIT_REPO_DIR/.git_index"
|
||||
@@ -225,7 +225,7 @@ _git_index_update_all_branches() {
|
||||
echo "=== Skipping $branch: remote and merge refs are not configured."
|
||||
fi
|
||||
done
|
||||
IFS=$' \t\n'
|
||||
unset IFS
|
||||
|
||||
# Update all remotes if there are any branches to update
|
||||
if [ -n "${branches[*]}" ]; then git fetch --all 2> /dev/null; fi
|
||||
@@ -268,7 +268,7 @@ function _git_index_batch_cmd() {
|
||||
cwd="$PWD"
|
||||
if [ -n "$1" ]; then
|
||||
echo -e "== Running command for $_bld_col$(_git_index_count)$_txt_col repos...\n"
|
||||
IFS=$' \t\n'
|
||||
unset IFS
|
||||
local base_path
|
||||
for base_path in $(sed -e "s/--.*//" "$GIT_REPO_DIR/.git_index" | \grep . | sort); do
|
||||
builtin cd "$base_path"
|
||||
@@ -313,7 +313,7 @@ if [ $shell = 'bash' ]; then
|
||||
else
|
||||
COMPREPLY=($(compgen -W '$(sed -e "s:.*/::" -e "s:$:/:" "$GIT_REPO_DIR/.git_index" | sort)' -- $curw))
|
||||
fi
|
||||
IFS=$' \t\n'
|
||||
unset IFS
|
||||
return 0
|
||||
}
|
||||
else
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
if test | sed -E 's///g' 2>/dev/null; then
|
||||
if sed -E 's///g' </dev/null &>/dev/null; then
|
||||
SED_REGEX_ARG="E"
|
||||
elif test | sed -r 's///g' 2>/dev/null; then
|
||||
elif sed -r 's///g' </dev/null &>/dev/null; then
|
||||
SED_REGEX_ARG="r"
|
||||
else
|
||||
echo "Cannot determine extended regex argument for sed! (Doesn't respond to either -E or -r)"
|
||||
@@ -21,7 +21,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 -$SED_REGEX_ARG -e "s/.*is aliased to \`//" -e "s/'$//"; }
|
||||
type whence > /dev/null 2>&1 || function whence() { LC_MESSAGES="C" type "$@" | sed -$SED_REGEX_ARG -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
|
||||
@@ -35,7 +35,7 @@ if [ "$shell_command_wrapping_enabled" = "true" ] || [ "$bash_command_wrapping_e
|
||||
fi
|
||||
fi
|
||||
|
||||
case "$(type $cmd 2>&1)" in
|
||||
case "$(LC_MESSAGES="C" type $cmd 2>&1)" in
|
||||
|
||||
# Don't do anything if command already aliased, or not found.
|
||||
*'exec_scmb_expand_args'*)
|
||||
@@ -52,7 +52,7 @@ if [ "$shell_command_wrapping_enabled" = "true" ] || [ "$bash_command_wrapping_e
|
||||
unalias $cmd
|
||||
|
||||
# Detect original $cmd type, and escape
|
||||
case "$(type $cmd 2>&1)" in
|
||||
case "$(LC_MESSAGES="C" 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 'find_binary' function
|
||||
@@ -108,50 +108,51 @@ fi
|
||||
|
||||
# Function wrapper around 'll'
|
||||
# Adds numbered shortcuts to output of ls -l, just like 'git status'
|
||||
unalias ll > /dev/null 2>&1; unset -f ll > /dev/null 2>&1
|
||||
function ls_with_file_shortcuts {
|
||||
local ll_output
|
||||
if [ "$_ls_bsd" != "BSD" ]; then
|
||||
ll_output="$(\ls -lhv --group-directories-first --color "$@")"
|
||||
else
|
||||
ll_output="$(CLICOLOR_FORCE=1 \ls -l -G "$@")"
|
||||
fi
|
||||
if [ "$shell_ls_aliases_enabled" = "true" ] && which ruby > /dev/null 2>&1; then
|
||||
unalias ll > /dev/null 2>&1; unset -f ll > /dev/null 2>&1
|
||||
function ls_with_file_shortcuts {
|
||||
local ll_output
|
||||
if [ "$_ls_bsd" != "BSD" ]; then
|
||||
ll_output="$(\ls -lhv --group-directories-first --color "$@")"
|
||||
else
|
||||
ll_output="$(CLICOLOR_FORCE=1 \ls -l -G "$@")"
|
||||
fi
|
||||
|
||||
if [[ $shell == "zsh" ]]; then
|
||||
# Ensure sh_word_split is on
|
||||
if setopt | grep -q shwordsplit; then SHWORDSPLIT_ON=true; fi
|
||||
setopt shwordsplit
|
||||
fi
|
||||
if [[ $shell == "zsh" ]]; then
|
||||
# Ensure sh_word_split is on
|
||||
if setopt | grep -q shwordsplit; then SHWORDSPLIT_ON=true; fi
|
||||
setopt shwordsplit
|
||||
fi
|
||||
|
||||
# Parse path from args
|
||||
OLDIFS="$IFS"; IFS=$'\n'
|
||||
for arg in $@; do
|
||||
if [ -d "$arg" ]; then local rel_path="${arg%/}"; fi
|
||||
done
|
||||
IFS="$OLDIFS"
|
||||
# Parse path from args
|
||||
IFS=$'\n'
|
||||
for arg in $@; do
|
||||
if [ -d "$arg" ]; then local rel_path="${arg%/}"; fi
|
||||
done
|
||||
unset IFS
|
||||
|
||||
# Replace user/group with user symbol, if defined at ~/.user_sym
|
||||
# Before : -rw-rw-r-- 1 ndbroadbent ndbroadbent 1.1K Sep 19 21:39 scm_breeze.sh
|
||||
# After : -rw-rw-r-- 1 𝐍 𝐍 1.1K Sep 19 21:39 scm_breeze.sh
|
||||
if [ -e $HOME/.user_sym ]; then
|
||||
# Little bit of ruby golf to rejustify the user/group/size columns after replacement
|
||||
function rejustify_ls_columns(){
|
||||
ruby -e "o=STDIN.read;re=/^(([^ ]* +){2})(([^ ]* +){3})/;\
|
||||
u,g,s=o.lines.map{|l|l[re,3]}.compact.map(&:split).transpose.map{|a|a.map(&:size).max+1};\
|
||||
puts o.lines.map{|l|l.sub(re){|m|\"%s%-#{u}s %-#{g}s%#{s}s \"%[\$1,*\$3.split]}}"
|
||||
}
|
||||
# Replace user/group with user symbol, if defined at ~/.user_sym
|
||||
# Before : -rw-rw-r-- 1 ndbroadbent ndbroadbent 1.1K Sep 19 21:39 scm_breeze.sh
|
||||
# After : -rw-rw-r-- 1 𝐍 𝐍 1.1K Sep 19 21:39 scm_breeze.sh
|
||||
if [ -e $HOME/.user_sym ]; then
|
||||
# Little bit of ruby golf to rejustify the user/group/size columns after replacement
|
||||
function rejustify_ls_columns(){
|
||||
ruby -e "o=STDIN.read;re=/^(([^ ]* +){2})(([^ ]* +){3})/;\
|
||||
u,g,s=o.lines.map{|l|l[re,3]}.compact.map(&:split).transpose.map{|a|a.map(&:size).max+1};\
|
||||
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 -$SED_REGEX_ARG "s/ $USER/ $(/bin/cat $HOME/.user_sym)/g" | rejustify_ls_columns)
|
||||
fi
|
||||
ll_output=$(echo "$ll_output" | \sed -$SED_REGEX_ARG "s/ $USER/ $(/bin/cat $HOME/.user_sym)/g" | rejustify_ls_columns)
|
||||
fi
|
||||
|
||||
if [ "$(echo "$ll_output" | wc -l)" -gt "50" ]; then
|
||||
echo -e "\033[33mToo many files to create shortcuts. Running plain ll command...\033[0m"
|
||||
echo "$ll_output"
|
||||
return 1
|
||||
fi
|
||||
if [ "$(echo "$ll_output" | wc -l)" -gt "50" ]; then
|
||||
echo -e "\033[33mToo many files to create shortcuts. Running plain ll command...\033[0m"
|
||||
echo "$ll_output"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Use ruby to inject numbers into ls output
|
||||
echo "$ll_output" | ruby -e "$( \cat <<EOF
|
||||
# Use ruby to inject numbers into ls output
|
||||
echo "$ll_output" | ruby -e "$( \cat <<EOF
|
||||
output = STDIN.read
|
||||
e = 1
|
||||
re = /^(([^ ]* +){8})/
|
||||
@@ -163,30 +164,31 @@ end
|
||||
EOF
|
||||
)"
|
||||
|
||||
# Set numbered file shortcut in variable
|
||||
local e=1
|
||||
local ll_files=''
|
||||
local file=''
|
||||
# Set numbered file shortcut in variable
|
||||
local e=1
|
||||
local ll_files=''
|
||||
local file=''
|
||||
|
||||
if [ -z $_ls_bsd ]; then
|
||||
ll_files="$(\ls -v --group-directories-first --color=never "$@")"
|
||||
else
|
||||
ll_files="$(\ls "$@")"
|
||||
fi
|
||||
if [ -z $_ls_bsd ]; then
|
||||
ll_files="$(\ls -v --group-directories-first --color=never "$@")"
|
||||
else
|
||||
ll_files="$(\ls "$@")"
|
||||
fi
|
||||
|
||||
OLDIFS="$IFS"; IFS=$'\n'
|
||||
for file in $ll_files; do
|
||||
if [ -n "$rel_path" ]; then file="$rel_path/$file"; fi
|
||||
export $git_env_char$e="$(eval $_abs_path_command \"${file//\"/\\\"}\")"
|
||||
if [ "${scmbDebug:-}" = "true" ]; then echo "Set \$$git_env_char$e => $file"; fi
|
||||
let e++
|
||||
done
|
||||
IFS="$OLDIFS"
|
||||
IFS=$'\n'
|
||||
for file in $ll_files; do
|
||||
if [ -n "$rel_path" ]; then file="$rel_path/$file"; fi
|
||||
export $git_env_char$e="$(eval $_abs_path_command \"${file//\"/\\\"}\")"
|
||||
if [ "${scmbDebug:-}" = "true" ]; then echo "Set \$$git_env_char$e => $file"; fi
|
||||
let e++
|
||||
done
|
||||
unset IFS
|
||||
|
||||
# Turn off shwordsplit unless it was on previously
|
||||
if [[ $shell == "zsh" ]] && [ -z "$SHWORDSPLIT_ON" ]; then unsetopt shwordsplit; fi
|
||||
}
|
||||
# Turn off shwordsplit unless it was on previously
|
||||
if [[ $shell == "zsh" ]] && [ -z "$SHWORDSPLIT_ON" ]; then unsetopt shwordsplit; fi
|
||||
}
|
||||
|
||||
# Setup aliases
|
||||
alias ll="exec_scmb_expand_args ls_with_file_shortcuts"
|
||||
alias la="ll -A"
|
||||
# Setup aliases
|
||||
alias ll="exec_scmb_expand_args ls_with_file_shortcuts"
|
||||
alias la="ll -A"
|
||||
fi
|
||||
|
||||
@@ -43,7 +43,7 @@ git_status_shortcuts() {
|
||||
if [ "${scmbDebug:-}" = "true" ]; then echo "Set \$$git_env_char$e => $file"; fi
|
||||
let e++
|
||||
done
|
||||
IFS=$' \t\n'
|
||||
unset IFS
|
||||
|
||||
if [ "${scmbDebug:-}" = "true" ]; then echo "------------------------"; fi
|
||||
# Print status
|
||||
@@ -91,7 +91,7 @@ git_silent_add_shortcuts() {
|
||||
echo -e "# Added '$file'"
|
||||
fi
|
||||
done
|
||||
IFS=$' \t\n'
|
||||
unset IFS
|
||||
echo "#"
|
||||
fi
|
||||
}
|
||||
@@ -158,7 +158,7 @@ _print_path() {
|
||||
# Execute a command with expanded args, e.g. Delete files 6 to 12: $ ge rm 6-12
|
||||
# Fails if command is a number or range (probably not worth fixing)
|
||||
exec_scmb_expand_args() {
|
||||
eval "$(scmb_expand_args "$@" | sed -e "s/\([][()<>^ \"']\)/"'\\\1/g')"
|
||||
eval "$(scmb_expand_args "$@" | sed -e "s/\([][|;()<>^ \"'&]\)/"'\\\1/g')"
|
||||
}
|
||||
|
||||
# Clear numbered env variables
|
||||
@@ -166,7 +166,12 @@ git_clear_vars() {
|
||||
local i
|
||||
for (( i=1; i<=$gs_max_changes; i++ )); do
|
||||
# Stop clearing after first empty var
|
||||
if [[ -z "$(eval echo "\${$git_env_char$i:-}")" ]]; then break; fi
|
||||
local env_var_i=${git_env_char}${i}
|
||||
if [[ -z "$(eval echo "\${$env_var_i:-}")" ]]; then
|
||||
break
|
||||
else
|
||||
unset $env_var_i
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
@@ -181,7 +186,7 @@ _git_resolve_merge_conflict() {
|
||||
git add "$file"
|
||||
echo -e "# Added $1 version of '$file'"
|
||||
done
|
||||
IFS=$' \t\n'
|
||||
unset IFS
|
||||
echo -e "# -- If you have finished resolving conflicts, commit the resolutions with 'git commit'"
|
||||
fi
|
||||
}
|
||||
@@ -233,7 +238,7 @@ git_commit_all() {
|
||||
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"
|
||||
git_commit_prompt "git add --all ."
|
||||
else
|
||||
echo "# No changed files to commit."
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user