From 7e1705e562a494b5d7a258bdf3d5eaa1ec4c4771 Mon Sep 17 00:00:00 2001 From: Will Owens Date: Fri, 23 Feb 2024 06:46:40 -0500 Subject: [PATCH] WIP --- .gitignore | 1 + flake.lock | 60 ++++++++++ flake.nix | 19 +++ git.scmbrc.example | 2 +- lib/git/aliases.sh | 41 ++++--- lib/git/branch_shortcuts.sh | 8 +- lib/git/fallback/status_shortcuts_shell.sh | 132 ++++++++++++++++----- lib/git/keybindings.sh | 35 +++--- lib/git/status_shortcuts.sh | 38 +++--- lib/git/tools.sh | 12 +- lib/scm_breeze.sh | 17 +-- test/lib/git/status_shortcuts_test.sh | 2 +- 12 files changed, 266 insertions(+), 101 deletions(-) create mode 100644 .gitignore create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..41fbeb0 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +**/result diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..e20ad06 --- /dev/null +++ b/flake.lock @@ -0,0 +1,60 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1705309234, + "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1707347730, + "narHash": "sha256-0etC/exQIaqC9vliKhc3eZE2Mm2wgLa0tj93ZF/egvM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "6832d0d99649db3d65a0e15fa51471537b2c56a6", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-23.11", + "type": "indirect" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..61d069d --- /dev/null +++ b/flake.nix @@ -0,0 +1,19 @@ +{ + description = "scm_breeze shell plugin for git and interactive shell"; + + inputs = { + flake-utils.url = "github:numtide/flake-utils"; + nixpkgs.url = "nixpkgs/nixos-23.11"; + }; + + outputs = { self, flake-utils, nixpkgs, ... }: + flake-utils.lib.eachDefaultSystem (system: + let pkgs = import nixpkgs { inherit system; }; + in rec { + formatter = pkgs.nixfmt; + packages = rec { + hello = pkgs.hello; + default = hello; + }; + }); +} diff --git a/git.scmbrc.example b/git.scmbrc.example index c97789b..aff8c78 100644 --- a/git.scmbrc.example +++ b/git.scmbrc.example @@ -126,6 +126,6 @@ git_add_and_amend_commit_keys="\C-xz" # CTRL+x, z # Expand numbered args for common shell commands shell_command_wrapping_enabled="true" # Here you can tweak the list of wrapped commands. -scmb_wrapped_shell_commands=(vim emacs gedit cat rm cp mv ln cd ls less subl code) +scmb_wrapped_shell_commands=("vim" "emacs" "gedit" "cat" "rm" "cp" "mv" "ln" "cd" "ls" "less" "subl" "code") # Add numbered shortcuts to output of ls -l, just like 'git status' shell_ls_aliases_enabled="true" diff --git a/lib/git/aliases.sh b/lib/git/aliases.sh index 0948540..0aefbb9 100644 --- a/lib/git/aliases.sh +++ b/lib/git/aliases.sh @@ -13,45 +13,48 @@ list_aliases() { alias | grep "$*" --color=never | sed -e 's/alias //' -e "s/=/: alias git_aliases="list_aliases git" # Remove any existing git alias or function -unalias git > /dev/null 2>&1 -unset -f git > /dev/null 2>&1 +unalias git >/dev/null 2>&1 +unset -f git >/dev/null 2>&1 # Use the full path to git to avoid infinite loop with git function export _git_cmd="$(bin_path 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 +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(){ +function git() { # Only expand args for git commands that deal with paths or branches case $1 in - commit|blame|add|log|rebase|merge|difftool|switch) - exec_scmb_expand_args "$_git_cmd" "$@";; - checkout|diff|rm|reset|restore) - exec_scmb_expand_args --relative "$_git_cmd" "$@";; - branch) - _scmb_git_branch_shortcuts "${@:2}";; - *) - "$_git_cmd" "$@";; + commit | blame | add | log | rebase | merge | difftool | switch) + exec_scmb_expand_args "$_git_cmd" "$@" + ;; + checkout | diff | rm | reset | restore) + exec_scmb_expand_args --relative "$_git_cmd" "$@" + ;; + branch) + _scmb_git_branch_shortcuts "${@:2}" + ;; + *) + "$_git_cmd" "$@" + ;; esac } _alias "$git_alias" "git" - # -------------------------------------------------------------------- # Thanks to Scott Bronson for coming up the following git tab completion workaround, # which I've altered slightly to be more flexible. # https://github.com/bronson/dotfiles/blob/731bfd951be68f395247982ba1fb745fbed2455c/.bashrc#L81 # (only works for bash) -__define_git_completion () { -eval " +__define_git_completion() { + eval " _git_$1_shortcut () { COMP_LINE=\"git $2 \${COMP_LINE/$1 }\" -let COMP_POINT+=$((4+${#2}-${#1})) +let COMP_POINT+=$((4 + ${#2} - ${#1})) COMP_WORDS=(git $2 \"\${COMP_WORDS[@]:1}\") let COMP_CWORD+=1 @@ -64,11 +67,13 @@ __git_wrap__git_main # Define git alias with tab completion # Usage: __git_alias -__git_alias () { +__git_alias() { if [ -n "$1" ]; then local alias_str cmd_prefix cmd cmd_args - alias_str="$1"; cmd_prefix="$2"; cmd="$3"; + alias_str="$1" + cmd_prefix="$2" + cmd="$3" if [ $# -gt 2 ]; then shift 3 2>/dev/null cmd_args=("$@") diff --git a/lib/git/branch_shortcuts.sh b/lib/git/branch_shortcuts.sh index 467b203..6d5f5ed 100644 --- a/lib/git/branch_shortcuts.sh +++ b/lib/git/branch_shortcuts.sh @@ -10,7 +10,8 @@ # Function wrapper around 'll' # Adds numbered shortcuts to output of ls -l, just like 'git status' -unalias $git_branch_alias > /dev/null 2>&1; unset -f $git_branch_alias > /dev/null 2>&1 +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 @@ -21,7 +22,8 @@ function _scmb_git_branch_shortcuts { fi # Use ruby to inject numbers into git branch output - ruby -e "$( cat < /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'` + local branch=$(git branch 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/') # Get project root if [ -d .git ]; then local project_root="$PWD" else - local project_root=$(git rev-parse --git-dir 2> /dev/null | sed "s%/\.git$%%g") + local project_root=$(git rev-parse --git-dir 2>/dev/null | sed "s%/\.git$%%g") fi # Colors @@ -46,9 +51,13 @@ git_status_shortcuts() { local c_cpy="\033[0;33m" local c_ign="\033[0;36m" # Following colors must be prepended with modifiers e.g. '\033[1;', '\033[0;' - local c_grp_1="33m"; local c_grp_2="31m"; local c_grp_3="32m"; local c_grp_4="36m" + local c_grp_1="33m" + local c_grp_2="31m" + local c_grp_3="32m" + local c_grp_4="36m" - local f=1; local e=1 # Counters for number of files, and ENV variables + local f=1 + local e=1 # Counters for number of files, and ENV variables echo -e "$c_dark#$c_rst On branch: $c_branch$branch$c_rst $c_dark| [$c_rst*$c_dark]$c_rst => \$$git_env_char*\n$c_dark#$c_rst" @@ -66,34 +75,98 @@ git_status_shortcuts() { # Index modification states msg="" case "$x$y" in - "DD") msg=" both deleted"; col="$c_del"; grp="2";; - "AU") msg=" added by us"; col="$c_new"; grp="2";; - "UD") msg="deleted by them"; col="$c_del"; grp="2";; - "UA") msg=" added by them"; col="$c_new"; grp="2";; - "DU") msg=" deleted by us"; col="$c_del"; grp="2";; - "AA") msg=" both added"; col="$c_new"; grp="2";; - "UU") msg=" both modified"; col="$c_mod"; grp="2";; - "M"?) msg=" modified"; col="$c_mod"; grp="1";; - "A"?) msg=" new file"; col="$c_new"; grp="1";; - "D"?) msg=" deleted"; col="$c_del"; grp="1";; - "R"?) msg=" renamed"; col="$c_ren"; grp="1";; - "C"?) msg=" copied"; col="$c_cpy"; grp="1";; - "??") msg="untracked"; col="$c_ign"; grp="4";; + "DD") + msg=" both deleted" + col="$c_del" + grp="2" + ;; + "AU") + msg=" added by us" + col="$c_new" + grp="2" + ;; + "UD") + msg="deleted by them" + col="$c_del" + grp="2" + ;; + "UA") + msg=" added by them" + col="$c_new" + grp="2" + ;; + "DU") + msg=" deleted by us" + col="$c_del" + grp="2" + ;; + "AA") + msg=" both added" + col="$c_new" + grp="2" + ;; + "UU") + msg=" both modified" + col="$c_mod" + grp="2" + ;; + "M"?) + msg=" modified" + col="$c_mod" + grp="1" + ;; + "A"?) + msg=" new file" + col="$c_new" + grp="1" + ;; + "D"?) + msg=" deleted" + col="$c_del" + grp="1" + ;; + "R"?) + msg=" renamed" + col="$c_ren" + grp="1" + ;; + "C"?) + msg=" copied" + col="$c_cpy" + grp="1" + ;; + "??") + msg="untracked" + col="$c_ign" + grp="4" + ;; esac if [ -n "$msg" ]; then # Store data at array index and add to group - stat_file[$f]=$file; stat_msg[$f]=$msg; stat_col[$f]=$col + stat_file[$f]=$file + stat_msg[$f]=$msg + stat_col[$f]=$col stat_grp[$grp]="${stat_grp[$grp]} $f" let f++ fi # Work tree modification states msg="" - if [[ "$y" == "M" ]]; then msg=" modified"; col="$c_mod"; grp="3"; fi + if [[ "$y" == "M" ]]; then + msg=" modified" + col="$c_mod" + grp="3" + fi # Don't show {Y} as deleted during a merge conflict. - if [[ "$y" == "D" && "$x" != "D" && "$x" != "U" ]]; then msg=" deleted"; col="$c_del"; grp="3"; fi + if [[ "$y" == "D" && "$x" != "D" && "$x" != "U" ]]; then + msg=" deleted" + col="$c_del" + grp="3" + fi if [ -n "$msg" ]; then - stat_file[$f]=$file; stat_msg[$f]=$msg; stat_col[$f]=$col + stat_file[$f]=$file + stat_msg[$f]=$msg + stat_col[$f]=$col stat_grp[$grp]="${stat_grp[$grp]} $f" let f++ fi @@ -135,10 +208,10 @@ _gs_output_file_group() { local absolute="$project_root/${stat_file[$i]}" local dest=$(readlink -f "$absolute") local pwd=$(readlink -f "$PWD") - relative="$(_gs_relative_path "$pwd" "${dest:-$absolute}" )" + relative="$(_gs_relative_path "$pwd" "${dest:-$absolute}")" fi - if [[ $f -gt 10 && $e -lt 10 ]]; then local pad=" "; else local pad=""; fi # (padding) + if [[ $f -gt 10 && $e -lt 10 ]]; then local pad=" "; else local pad=""; fi # (padding) echo -e "$c_hash#$c_rst ${stat_col[$i]}${stat_msg[$i]}:\ $pad$c_dark [$c_rst$e$c_dark] $c_group$relative$c_rst" # Export numbered variables in the order they are displayed. @@ -152,14 +225,15 @@ $pad$c_dark [$c_rst$e$c_dark] $c_group$relative$c_rst" } # Show relative path if current directory is not project root -_gs_relative_path(){ +_gs_relative_path() { # Credit to 'pini' for the following script. # (http://stackoverflow.com/questions/2564634/bash-convert-absolute-path-into-relative-path-given-a-current-directory) - target=$2; common_part=$1; back="" + target=$2 + common_part=$1 + back="" while [[ -n "${common_part}" && "${target#$common_part}" == "${target}" ]]; do common_part="${common_part%/*}" back="../${back}" done echo "${back}${target#$common_part/}" } - diff --git a/lib/git/keybindings.sh b/lib/git/keybindings.sh index 2886591..218811d 100644 --- a/lib/git/keybindings.sh +++ b/lib/git/keybindings.sh @@ -30,24 +30,25 @@ if [[ "$git_keyboard_shortcuts_enabled" = "true" ]]; then RETURN_CHAR="\n" fi - # 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""$RETURN_CHAR" - _bind "$git_add_and_commit_keys" " \033[1~ git_add_and_commit ""$RETURN_CHAR" - _bind "$git_commit_all_with_ci_skip_keys" " \033[1~ GIT_COMMIT_MSG_SUFFIX='[ci skip]' git_commit_all ""$RETURN_CHAR" - _bind "$git_add_and_amend_commit_keys" " git add --all . && git commit --amend -C HEAD""$RETURN_CHAR" - else - _bind "$git_commit_all_keys" "\" git_commit_all$RETURN_CHAR\"" - _bind "$git_add_and_commit_keys" "\"\C-A git_add_and_commit $RETURN_CHAR\"" - _bind "$git_commit_all_with_ci_skip_keys" "\"\C-A GIT_COMMIT_MSG_SUFFIX='[ci skip]' git_commit_all $RETURN_CHAR\"" - _bind "$git_add_and_amend_commit_keys" "\" git add --all . && git commit --amend -C HEAD$RETURN_CHAR\"" - fi + # Uses emacs style keybindings, so vi mode is not supported for now + if ! set -o | grep -q '^vi .*on$'; then + if breeze_shell_is "zsh"; then + _bind "$git_commit_all_keys" " git_commit_all""$RETURN_CHAR" + _bind "$git_add_and_commit_keys" " \033[1~ git_add_and_commit ""$RETURN_CHAR" + _bind "$git_commit_all_with_ci_skip_keys" " \033[1~ GIT_COMMIT_MSG_SUFFIX='[ci skip]' git_commit_all ""$RETURN_CHAR" + _bind "$git_add_and_amend_commit_keys" " git add --all . && git commit --amend -C HEAD""$RETURN_CHAR" + else + _bind "$git_commit_all_keys" "\" git_commit_all$RETURN_CHAR\"" + _bind "$git_add_and_commit_keys" "\"\C-A git_add_and_commit $RETURN_CHAR\"" + _bind "$git_commit_all_with_ci_skip_keys" "\"\C-A GIT_COMMIT_MSG_SUFFIX='[ci skip]' git_commit_all $RETURN_CHAR\"" + _bind "$git_add_and_amend_commit_keys" "\" git add --all . && git commit --amend -C HEAD$RETURN_CHAR\"" fi + fi - # Commands are prepended with a space so that they won't be added to history. - # Make sure this is turned on with: - # zsh: setopt histignorespace histignoredups - # bash: HISTCONTROL=ignorespace:ignoredups + # Commands are prepended with a space so that they won't be added to history. + # Make sure this is turned on with: + # zsh: setopt histignorespace histignoredups + # bash: HISTCONTROL=ignorespace:ignoredups + ;; esac fi diff --git a/lib/git/status_shortcuts.sh b/lib/git/status_shortcuts.sh index 9f40e53..dde9f3f 100644 --- a/lib/git/status_shortcuts.sh +++ b/lib/git/status_shortcuts.sh @@ -82,7 +82,7 @@ git_silent_add_shortcuts() { if [ -n "$1" ]; then # Expand args and process resulting set of files. local args - eval args="$(scmb_expand_args "$@")" # populate $args array + eval args="$(scmb_expand_args "$@")" # populate $args array for file in "${args[@]}"; do # Use 'git rm' if file doesn't exist and 'ga_auto_remove' is enabled. if [[ $ga_auto_remove = yes && ! -e $file ]]; then @@ -99,16 +99,19 @@ git_silent_add_shortcuts() { # Prints a list of all files affected by a given SHA1, # and exports numbered environment variables for each file. -git_show_affected_files(){ +git_show_affected_files() { fail_if_not_git_repo || return 1 - local f=0 # File count + local f=0 # File count # Show colored revision and commit message - echo -n "# "; git show --oneline --name-only "$@" | head -n1; echo "# " + echo -n "# " + git show --oneline --name-only "$@" | head -n1 + echo "# " for file in $(git show --pretty="format:" --name-only "$@" | \grep -v '^$'); do let f++ - export $git_env_char$f=$file # Export numbered variable. + export $git_env_char$f=$file # Export numbered variable. echo -e "# \033[2;37m[\033[0m$f\033[2;37m]\033[0m $file" - done; echo "# " + done + echo "# " } # Allows expansion of numbered shortcuts, ranges of shortcuts, or standard paths. @@ -124,20 +127,20 @@ scmb_expand_args() { fi local args - args=() # initially empty array. zsh 5.0.2 from Ubuntu 14.04 requires this to be separated + args=() # initially empty array. zsh 5.0.2 from Ubuntu 14.04 requires this to be separated for arg in "$@"; do - if [[ "$arg" =~ ^[0-9]{0,4}$ ]] ; then # Substitute $e{*} variables for any integers + if [[ "$arg" =~ ^[0-9]{0,4}$ ]]; then # Substitute $e{*} variables for any integers if [ -e "$arg" ]; then # Don't expand files or directories with numeric names args+=("$arg") else args+=("$(_print_path "$relative" "$git_env_char$arg")") fi - elif [[ "$arg" =~ ^[0-9]+-[0-9]+$ ]]; then # Expand ranges into $e{*} variables + elif [[ "$arg" =~ ^[0-9]+-[0-9]+$ ]]; then # Expand ranges into $e{*} variables for i in $(eval echo {${arg/-/..}}); do args+=("$(_print_path "$relative" "$git_env_char$i")") done - else # Otherwise, treat $arg as a normal string. + else # Otherwise, treat $arg as a normal string. args+=("$arg") fi done @@ -167,14 +170,14 @@ _print_path() { # Fails if command is a number or range (probably not worth fixing) exec_scmb_expand_args() { local args - eval "args=$(scmb_expand_args "$@")" # populate $args array + eval "args=$(scmb_expand_args "$@")" # populate $args array _safe_eval "${args[@]}" } # Clear numbered env variables git_clear_vars() { local i - for (( i=1; i<=$gs_max_changes; i++ )); do + for ((i = 1; i <= $gs_max_changes; i++)); do # Stop clearing after first empty var local env_var_i=${git_env_char}${i} if [[ -z "$(eval echo "\${$env_var_i:-}")" ]]; then @@ -190,18 +193,17 @@ _git_resolve_merge_conflict() { if [ -n "$2" ]; then # Expand args and process resulting set of files. local args - eval "args=$(scmb_expand_args "$@")" # populate $args array + eval "args=$(scmb_expand_args "$@")" # populate $args array for file in "${args[@]:2}"; do - git checkout "--$1""s" "$file" # "--$1""s" is expanded to --ours or --theirs + git checkout "--$1""s" "$file" # "--$1""s" is expanded to --ours or --theirs git add "$file" echo -e "# Added $1 version of '$file'" done echo -e "# -- If you have finished resolving conflicts, commit the resolutions with 'git commit'" fi } -ours(){ _git_resolve_merge_conflict "our" "$@"; } -theirs(){ _git_resolve_merge_conflict "their" "$@"; } - +ours() { _git_resolve_merge_conflict "our" "$@"; } +theirs() { _git_resolve_merge_conflict "their" "$@"; } # Git commit prompts # ------------------------------------------------------------------------------ @@ -292,7 +294,7 @@ git_add_and_commit() ( git_silent_add_shortcuts "$@" changes=$(git diff --cached --numstat | wc -l) if [ "$changes" -gt 0 ]; then - git_status_shortcuts 1 # only show staged changes + git_status_shortcuts 1 # only show staged changes git_commit_prompt else echo "# No staged changes to commit." diff --git a/lib/git/tools.sh b/lib/git/tools.sh index 313c627..2076088 100644 --- a/lib/git/tools.sh +++ b/lib/git/tools.sh @@ -18,21 +18,21 @@ git_remove_history() { # Make sure we're at the root of a git repo if [ ! -d .git ]; then - echo "Error: must run this script from the root of a git repository" - return + echo "Error: must run this script from the root of a git repository" + return fi # Remove all paths passed as arguments from the history of the repo local files files=("$@") $_git_cmd filter-branch --index-filter "$_git_cmd rm -rf --cached --ignore-unmatch ${files[*]}" HEAD # Remove the temporary history git-filter-branch otherwise leaves behind for a long time - rm -rf .git/refs/original/ && $_git_cmd reflog expire --all && $_git_cmd gc --aggressive --prune + rm -rf .git/refs/original/ && $_git_cmd reflog expire --all && $_git_cmd gc --aggressive --prune } # Set default remote and merge for a git branch (pull and push) # Usage: git_set_default_remote(branch = master, remote = origin) git_set_default_remote() { - curr_branch=$($_git_cmd branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/') + curr_branch=$($_git_cmd branch 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/') if [ -n "$1" ]; then branch="$1"; else branch="$curr_branch"; fi if [ -n "$2" ]; then remote="$2"; else remote="origin"; fi echo "branch.$branch.remote: $remote" @@ -45,7 +45,7 @@ git_set_default_remote() { # Usage: git_ignore [rule] [ignore_file=.gitignore] __git_ignore() { if [ -n "$2" ]; then local f="$2"; else local f=".gitignore"; fi - if [ -n "$1" ] && ! ([ -e $f ] && grep -q "$1" $f); then echo "$1" >> $f; fi + if [ -n "$1" ] && ! ([ -e $f ] && grep -q "$1" $f); then echo "$1" >>$f; fi } # Always expand args git_ignore() { @@ -77,7 +77,7 @@ git_exclude_basename() { # git_bisect_grep() { if [ -z "$2" ]; then - echo "Usage: $0 "; + echo "Usage: $0 " return fi if [ -n "$3" ]; then search_path="$3"; else search_path="."; fi diff --git a/lib/scm_breeze.sh b/lib/scm_breeze.sh index f5a06ed..2352180 100644 --- a/lib/scm_breeze.sh +++ b/lib/scm_breeze.sh @@ -45,21 +45,22 @@ disable_nullglob() { } # Alias wrapper that ignores errors if alias is not defined. -_safe_alias(){ alias "$@" 2> /dev/null; } +_safe_alias() { alias "$@" 2>/dev/null; } _alias() { if [ -n "$1" ]; then - local alias_str="$1"; local cmd="$2" + local alias_str="$1" + local cmd="$2" _safe_alias $alias_str="$cmd" fi } # Quote the contents of "$@" function token_quote { - # Older versions of {ba,z}sh don't support the built-in quoting, so fall back to printf %q + # Older versions of {ba,z}sh don't support the built-in quoting, so fall back to printf %q local quoted - quoted=() # Assign separately for zsh 5.0.2 of Ubuntu 14.04 + quoted=() # Assign separately for zsh 5.0.2 of Ubuntu 14.04 for token; do - quoted+=( "$(printf '%q' "$token")" ) + quoted+=("$(printf '%q' "$token")") done printf '%s\n' "${quoted[*]}" @@ -109,7 +110,7 @@ export GIT_BINARY=$(find_binary git) update_scm_breeze() { currDir=$PWD cd "$scmbDir" - oldHEAD=$(git rev-parse HEAD 2> /dev/null) + oldHEAD=$(git rev-parse HEAD 2>/dev/null) git pull origin master # Reload latest version of '_create_or_patch_scmbrc' function source "$scmbDir/lib/scm_breeze.sh" @@ -131,8 +132,8 @@ _create_or_patch_scmbrc() { # If file exists, attempt to update it with any new settings elif [ -n "$1" ]; then # Create diff of example file, substituting example file for user's config. - git diff $1 "$prefix""scmbrc.example" | sed "s/$prefix""scmbrc.example/.$prefix""scmbrc/g" >| $patchfile - if [ -s $patchfile ]; then # If patchfile is not empty + git diff $1 "$prefix""scmbrc.example" | sed "s/$prefix""scmbrc.example/.$prefix""scmbrc/g" >|$patchfile + if [ -s $patchfile ]; then # If patchfile is not empty cd "$HOME" # If the patch cannot be applied cleanly, show the updates and tell user to update file manually. if ! patch -f "$HOME/.$prefix""scmbrc" $patchfile; then diff --git a/test/lib/git/status_shortcuts_test.sh b/test/lib/git/status_shortcuts_test.sh index 5ba6a7b..40a0854 100755 --- a/test/lib/git/status_shortcuts_test.sh +++ b/test/lib/git/status_shortcuts_test.sh @@ -184,7 +184,7 @@ test_git_status_shortcuts() { # (This is needed so that env variables are exported in the current shell) temp_file=$(mktemp -t scm_breeze.XXXXXXXXXX) git_status_shortcuts >$temp_file - git_status=$(<$temp_file strip_colors) + git_status=$(strip_colors <$temp_file) assertIncludes "$git_status" "new file: *\[1\] *new_file" || return assertIncludes "$git_status" "deleted: *\[2\] *deleted_file" || return