Merge branch 'master' of git://github.com/g5pw/scm_breeze into g5pw-master
Conflicts: lib/git/shell_shortcuts.sh
This commit is contained in:
@@ -74,31 +74,33 @@ fi
|
|||||||
|
|
||||||
|
|
||||||
# BSD ls is different to Linux (GNU) ls
|
# BSD ls is different to Linux (GNU) ls
|
||||||
_uname="$(uname)"
|
# Test for BSD ls
|
||||||
if [ "$_uname" = "Linux" ]; then
|
if ! ls --color=auto > /dev/null 2>&1; then
|
||||||
# Linux ls commands
|
# ls is BSD
|
||||||
_ll_command="ls -lhv --group-directories-first --color"
|
_ls_bsd="BSD"
|
||||||
_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"
|
|
||||||
# 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)'"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$_ll_command" ]; then
|
# Test if readlink supports -f option, otherwise use perl (a bit slower)
|
||||||
# Function wrapper around 'll'
|
if ! readlink -f > /dev/null 2>&1; then
|
||||||
# Adds numbered shortcuts to output of ls -l, just like 'git status'
|
_abs_path_command='perl -e "use Cwd "abs_path"; print abs_path(shift)"'
|
||||||
unalias ll > /dev/null 2>&1; unset -f ll > /dev/null 2>&1
|
else
|
||||||
function ls_with_file_shortcuts {
|
_abs_path_command="readlink -f"
|
||||||
# Wrap each arg in quotes
|
fi
|
||||||
local wrapped_args
|
|
||||||
for arg in "$@"; do wrapped_args+=" \"$arg\""; done
|
# Function wrapper around 'll'
|
||||||
local ll_output="$(eval $_ll_command $wrapped_args)"
|
# 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 [ -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
|
# Parse path from args
|
||||||
|
zsh_compat # Ensure sh_word_split is on
|
||||||
OLDIFS="$IFS"; IFS=$'\n'
|
OLDIFS="$IFS"; IFS=$'\n'
|
||||||
for arg in $@; do
|
for arg in $@; do
|
||||||
if [ -d "$arg" ]; then local rel_path="${arg%/}"; fi
|
if [ -d "$arg" ]; then local rel_path="${arg%/}"; fi
|
||||||
@@ -126,23 +128,34 @@ if [ -n "$_ll_command" ]; then
|
|||||||
|
|
||||||
# Use ruby to inject numbers into ls output
|
# Use ruby to inject numbers into ls output
|
||||||
ruby -e "$( cat <<EOF
|
ruby -e "$( cat <<EOF
|
||||||
output = "$ll_output"
|
output = "$ll_output"
|
||||||
e = 1
|
e = 1
|
||||||
re = /^(([^ ]* +){8})/
|
re = /^(([^ ]* +){8})/
|
||||||
output.lines.each do |line|
|
output.lines.each do |line|
|
||||||
next unless line.match(re)
|
next unless line.match(re)
|
||||||
puts line.sub(re, "\\\1\e[2;37m[\e[0m#{e}\e[2;37m]\e[0m" << (e < 10 ? " " : " "))
|
puts line.sub(re, "\\\1\e[2;37m[\e[0m#{e}\e[2;37m]\e[0m" << (e < 10 ? " " : " "))
|
||||||
e += 1
|
e += 1
|
||||||
end
|
end
|
||||||
EOF
|
EOF
|
||||||
)"
|
)"
|
||||||
|
|
||||||
# Set numbered file shortcut in variable
|
# Set numbered file shortcut in variable
|
||||||
local e=1
|
local e=1
|
||||||
local ll_files="$(eval $_ll_sys_command $wrapped_args)"
|
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'
|
OLDIFS="$IFS"; IFS=$'\n'
|
||||||
if [[ $shell == "zsh" ]]; then setopt shwordsplit; fi
|
if [[ $shell == "zsh" ]]; then
|
||||||
|
# Ensure sh_word_split is on
|
||||||
|
zsh_compat
|
||||||
|
setopt shwordsplit
|
||||||
|
fi
|
||||||
for file in $ll_files; do
|
for file in $ll_files; do
|
||||||
if [ -n "$rel_path" ]; then file="$rel_path/$file"; fi
|
if [ -n "$rel_path" ]; then file="$rel_path/$file"; fi
|
||||||
export $git_env_char$e="$(eval $_abs_path_command \"$file\")"
|
export $git_env_char$e="$(eval $_abs_path_command \"$file\")"
|
||||||
@@ -151,8 +164,7 @@ EOF
|
|||||||
done
|
done
|
||||||
IFS="$OLDIFS"
|
IFS="$OLDIFS"
|
||||||
if [[ $shell == "zsh" ]]; then unsetopt shwordsplit; fi
|
if [[ $shell == "zsh" ]]; then unsetopt shwordsplit; fi
|
||||||
}
|
}
|
||||||
fi
|
|
||||||
|
|
||||||
# Setup aliases
|
# Setup aliases
|
||||||
alias ll="exec_scmb_expand_args ls_with_file_shortcuts"
|
alias ll="exec_scmb_expand_args ls_with_file_shortcuts"
|
||||||
|
|||||||
Reference in New Issue
Block a user