[shell_aliases] try fix array looping
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
# Released under the LGPL (GNU Lesser General Public License)
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
if sed -E 's///g' </dev/null &>/dev/null; then
|
||||
SED_REGEX_ARG="E"
|
||||
elif sed -r 's///g' </dev/null &>/dev/null; then
|
||||
@@ -13,7 +12,6 @@ else
|
||||
echo "Cannot determine extended regex argument for sed! (Doesn't respond to either -E or -r)"
|
||||
fi
|
||||
|
||||
|
||||
# Wrap common commands with numeric argument expansion.
|
||||
# Prepends everything with exec_scmb_expand_args,
|
||||
# even if commands are already aliases or functions
|
||||
@@ -23,7 +21,7 @@ if [ "$shell_command_wrapping_enabled" = "true" ] || [ "$bash_command_wrapping_e
|
||||
# Define 'whence' for bash, to get the value of an alias
|
||||
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 $scmb_wrapped_shell_commands; do
|
||||
for cmd in "${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
|
||||
@@ -39,10 +37,12 @@ if [ "$shell_command_wrapping_enabled" = "true" ] || [ "$bash_command_wrapping_e
|
||||
|
||||
# Don't do anything if command already aliased, or not found.
|
||||
*'exec_scmb_expand_args'*)
|
||||
if [ "${scmbDebug:-}" = "true" ]; then echo "SCMB: $cmd is already wrapped"; fi;;
|
||||
if [ "${scmbDebug:-}" = "true" ]; then echo "SCMB: $cmd is already wrapped"; fi
|
||||
;;
|
||||
|
||||
*'not found'*)
|
||||
if [ "${scmbDebug:-}" = "true" ]; then echo "SCMB: $cmd not found!"; fi;;
|
||||
if [ "${scmbDebug:-}" = "true" ]; then echo "SCMB: $cmd not found!"; fi
|
||||
;;
|
||||
|
||||
*'aliased to'* | *'is an alias for'*)
|
||||
if [ "${scmbDebug:-}" = "true" ]; then echo "SCMB: $cmd is an alias"; fi
|
||||
@@ -62,7 +62,8 @@ if [ "$shell_command_wrapping_enabled" = "true" ] || [ "$bash_command_wrapping_e
|
||||
# Expand original command into full path, to avoid infinite loops
|
||||
local expanded_alias="$(echo $original_alias | sed -$SED_REGEX_ARG "s%(^| )$cmd($| )%\\1$escaped_cmd\\2%")"
|
||||
# Wrap previous alias with escaped command
|
||||
alias $cmd="exec_scmb_expand_args $expanded_alias";;
|
||||
alias $cmd="exec_scmb_expand_args $expanded_alias"
|
||||
;;
|
||||
|
||||
*'is a'*'function'*)
|
||||
if [ "${scmbDebug:-}" = "true" ]; then echo "SCMB: $cmd is a function"; fi
|
||||
@@ -71,18 +72,21 @@ if [ "$shell_command_wrapping_enabled" = "true" ] || [ "$bash_command_wrapping_e
|
||||
# Remove function
|
||||
unset -f "$cmd"
|
||||
# Create function that wraps old function
|
||||
eval "${cmd}(){ exec_scmb_expand_args __original_${cmd} \"\$@\"; }";;
|
||||
eval "${cmd}(){ exec_scmb_expand_args __original_${cmd} \"\$@\"; }"
|
||||
;;
|
||||
|
||||
*'is a shell builtin'*)
|
||||
if [ "${scmbDebug:-}" = "true" ]; then echo "SCMB: $cmd is a shell builtin"; fi
|
||||
# Handle shell builtin commands
|
||||
alias $cmd="exec_scmb_expand_args builtin $cmd";;
|
||||
alias $cmd="exec_scmb_expand_args builtin $cmd"
|
||||
;;
|
||||
|
||||
*)
|
||||
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 with 'find_binary' function
|
||||
alias $cmd="exec_scmb_expand_args '$(find_binary $cmd)'";;
|
||||
alias $cmd="exec_scmb_expand_args '$(find_binary $cmd)'"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
# Clean up
|
||||
@@ -91,7 +95,6 @@ if [ "$shell_command_wrapping_enabled" = "true" ] || [ "$bash_command_wrapping_e
|
||||
_git_wrap_commands
|
||||
fi
|
||||
|
||||
|
||||
# Function wrapper around 'll'
|
||||
# Adds numbered shortcuts to output of ls -l, just like 'git status'
|
||||
if [ "$shell_ls_aliases_enabled" = "true" ] && builtin command -v ruby >/dev/null 2>&1; then
|
||||
@@ -111,7 +114,8 @@ if [ "$shell_ls_aliases_enabled" = "true" ] && builtin command -v ruby > /dev/nu
|
||||
_abs_path_command=(perl -e 'use Cwd abs_path; print abs_path(shift)')
|
||||
fi
|
||||
|
||||
unalias ll > /dev/null 2>&1; unset -f ll > /dev/null 2>&1
|
||||
unalias ll >/dev/null 2>&1
|
||||
unset -f ll >/dev/null 2>&1
|
||||
function ls_with_file_shortcuts {
|
||||
local ll_output
|
||||
local ll_command # Ensure sort ordering of the two invocations is the same
|
||||
@@ -168,12 +172,12 @@ if [ "$shell_ls_aliases_enabled" = "true" ] && builtin command -v ruby > /dev/nu
|
||||
local USER_SYM=$(/bin/cat $HOME/.user_sym)
|
||||
if [ -f "$HOME/.staff_sym" ]; then
|
||||
local STAFF_SYM=$(/bin/cat $HOME/.staff_sym)
|
||||
ll_output=$(echo "$ll_output" | \
|
||||
\sed -$SED_REGEX_ARG "s/ $USER staff/ $USER_SYM $STAFF_SYM /g" | \
|
||||
ll_output=$(echo "$ll_output" |
|
||||
\sed -$SED_REGEX_ARG "s/ $USER staff/ $USER_SYM $STAFF_SYM /g" |
|
||||
rejustify_ls_columns)
|
||||
else
|
||||
ll_output=$(echo "$ll_output" | \
|
||||
\sed -$SED_REGEX_ARG "s/ $USER/ $USER_SYM /g" | \
|
||||
ll_output=$(echo "$ll_output" |
|
||||
\sed -$SED_REGEX_ARG "s/ $USER/ $USER_SYM /g" |
|
||||
rejustify_ls_columns)
|
||||
fi
|
||||
fi
|
||||
@@ -186,7 +190,8 @@ if [ "$shell_ls_aliases_enabled" = "true" ] && builtin command -v ruby > /dev/nu
|
||||
fi
|
||||
|
||||
# Use ruby to inject numbers into ls output
|
||||
echo "$ll_output" | ruby -e "$( \cat <<EOF
|
||||
echo "$ll_output" | ruby -e "$(
|
||||
\cat <<EOF
|
||||
output = STDIN.read
|
||||
e = 1
|
||||
re = /^(([^ ]* +){8})/
|
||||
|
||||
@@ -11,7 +11,9 @@ export scmbDir="$( cd -P "$( dirname "$0" )" && pwd )/../../.."
|
||||
|
||||
# Zsh compatibility
|
||||
if [ -n "${ZSH_VERSION:-}" ]; then
|
||||
shell="zsh"; SHUNIT_PARENT=$0; setopt shwordsplit
|
||||
shell="zsh"
|
||||
SHUNIT_PARENT=$0
|
||||
setopt shwordsplit
|
||||
else
|
||||
# Bash needs this option so that 'alias' works in a non-interactive shell
|
||||
shopt -s expand_aliases
|
||||
@@ -25,7 +27,7 @@ source "$scmbDir/lib/scm_breeze.sh"
|
||||
#-----------------------------------------------------------------------------
|
||||
oneTimeSetUp() {
|
||||
export shell_command_wrapping_enabled="true"
|
||||
export scmb_wrapped_shell_commands="not_found cat rm cp mv ln cd sed"
|
||||
export scmb_wrapped_shell_commands=("not_found" "cat" "rm" "cp" "mv" "ln" "cd" "sed")
|
||||
export shell_ls_aliases_enabled="true"
|
||||
|
||||
alias rvm="test" # Ensure tests run if RVM isn't loaded but $HOME/.rvm is present
|
||||
@@ -61,7 +63,6 @@ assertAliasEquals(){
|
||||
assertEquals "$1" "$(whence $2)"
|
||||
}
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Setup and tear down
|
||||
#-----------------------------------------------------------------------------
|
||||
@@ -70,7 +71,6 @@ setUp() {
|
||||
unset QUOTING_STYLE # Use default quoting style for ls
|
||||
}
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Unit tests
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user