From bf08619f70d2153155971d4c1805c68e290a237f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aljaz=CC=8C=20=22g5pw=22=20Srebrnic=CC=8C?= Date: Mon, 22 Oct 2012 19:31:13 +0200 Subject: [PATCH 1/4] Get rid of escaped quotes --- 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 72bfb4b..c60f044 100644 --- a/lib/git/shell_shortcuts.sh +++ b/lib/git/shell_shortcuts.sh @@ -85,7 +85,7 @@ elif [ "$_uname" = "Darwin" ]; then _ll_command="CLICOLOR_FORCE=1 ls -l -G" _ll_sys_command="ls" # Use perl abs_path, since readlink -f isn't available on OS X - _abs_path_command="perl -e 'use Cwd \"abs_path\"; print abs_path(shift)'" + _abs_path_command='perl -e "use Cwd "abs_path"; print abs_path(shift)"' fi if [ -n "$_ll_command" ]; then From 7e3d7825d2777daf9069243ebec44c242f628afe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aljaz=CC=8C=20=22g5pw=22=20Srebrnic=CC=8C?= Date: Mon, 22 Oct 2012 19:37:55 +0200 Subject: [PATCH 2/4] Test for command type, not architecture This patch modifies the way available commands are tested; If a Mac user installs and uses GNU ls it is correctly detected and used. the ls_with_file_shortcuts now works on ZSH. It was failing with "command not found" due to parameters passed in $_ll_command which were interpreted as a command name. --- lib/git/shell_shortcuts.sh | 41 +++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/lib/git/shell_shortcuts.sh b/lib/git/shell_shortcuts.sh index c60f044..20ecde6 100644 --- a/lib/git/shell_shortcuts.sh +++ b/lib/git/shell_shortcuts.sh @@ -74,18 +74,22 @@ fi # BSD ls is different to Linux (GNU) ls -_uname="$(uname)" -if [ "$_uname" = "Linux" ]; then - # Linux ls commands - _ll_command="ls -lhv --group-directories-first --color" - _ll_sys_command="ls -v --group-directories-first --color=never" - _abs_path_command="readlink -f" -elif [ "$_uname" = "Darwin" ]; then - # OS X ls commands - _ll_command="CLICOLOR_FORCE=1 ls -l -G" - _ll_sys_command="ls" +# test for BSD ls +ls --color=auto > /dev/null 2>&1 +if [ $? -ne 0 ]; then + # ls is BSD + _ls_bsd="BSD" +fi + +# test readlink +type readlink > /dev/null 2>&1 +if [ $? -ne 0 ]; then + # no readlink # Use perl abs_path, since readlink -f isn't available on OS X _abs_path_command='perl -e "use Cwd "abs_path"; print abs_path(shift)"' +else + #readlink + _abs_path_command="readlink -f" fi if [ -n "$_ll_command" ]; then @@ -93,7 +97,13 @@ if [ -n "$_ll_command" ]; then # 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="$($_ll_command "$@")" + local ll_output='' + + if [ -z $_ls_bsd ]; then + ll_output="$(ls -lhv --group-directories-first --color "$@")" + else + ll_output="$(CLICOLOR_FORCE=1 ls -l -G "$@")" + fi # Parse path from args OLDIFS="$IFS"; IFS=$'\n' @@ -136,7 +146,14 @@ EOF # Set numbered file shortcut in variable local e=1 - local ll_files="$($_ll_sys_command "$@")" + local ll_files='' + local file='' + + 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 From 2bd5d3ea2fcb85f9b5fd12ac7554f379f8e972cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aljaz=CC=8C=20=22g5pw=22=20Srebrnic=CC=8C?= Date: Mon, 22 Oct 2012 19:39:20 +0200 Subject: [PATCH 3/4] ZSH compatibility fix This fixes ZSH compatibility by ensuring sh_word_split is on. --- lib/git/shell_shortcuts.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/git/shell_shortcuts.sh b/lib/git/shell_shortcuts.sh index 20ecde6..2ceaf50 100644 --- a/lib/git/shell_shortcuts.sh +++ b/lib/git/shell_shortcuts.sh @@ -106,6 +106,7 @@ if [ -n "$_ll_command" ]; then fi # Parse path from args + zsh_compat # Ensure sh_word_split is on OLDIFS="$IFS"; IFS=$'\n' for arg in $@; do if [ -d "$arg" ]; then local rel_path="${arg%/}"; fi @@ -155,6 +156,7 @@ EOF ll_files="$(ls "$@")" fi + zsh_compat # Ensure sh_word_split is on OLDIFS="$IFS"; IFS=$'\n' for file in $ll_files; do if [ -n "$rel_path" ]; then file="$rel_path/$file"; fi From 905bd3d09496aadf919fbb6ce984f02519ddfe09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aljaz=CC=8C=20=22g5pw=22=20Srebrnic=CC=8C?= Date: Mon, 22 Oct 2012 19:40:58 +0200 Subject: [PATCH 4/4] Fix small bug $_ll_command is no longer defined, so the test evaluates to false, failing to include the ls_with_file_shortcuts function. --- lib/git/shell_shortcuts.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/git/shell_shortcuts.sh b/lib/git/shell_shortcuts.sh index 2ceaf50..432faaa 100644 --- a/lib/git/shell_shortcuts.sh +++ b/lib/git/shell_shortcuts.sh @@ -92,7 +92,6 @@ else _abs_path_command="readlink -f" fi -if [ -n "$_ll_command" ]; then # 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 @@ -166,7 +165,6 @@ EOF done IFS="$OLDIFS" } -fi # Setup aliases alias ll="exec_scmb_expand_args ls_with_file_shortcuts"