Add 'll' support for paths with spaces
This commit is contained in:
@@ -88,24 +88,25 @@ elif [ "$_uname" = "Darwin" ]; then
|
|||||||
_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
|
fi
|
||||||
|
|
||||||
# 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]}}"
|
|
||||||
}
|
|
||||||
_ls_processor="| sed \"s/ $USER/ \$(/bin/cat $HOME/.user_sym)/g\" | rejustify_ls_columns"
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
if [ -n "$_ll_command" ]; then
|
if [ -n "$_ll_command" ]; then
|
||||||
# Function wrapper around 'll'
|
# Function wrapper around 'll'
|
||||||
# Adds numbered shortcuts to output of ls -l, just like 'git status'
|
# 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
|
unalias ll > /dev/null 2>&1; unset -f ll > /dev/null 2>&1
|
||||||
function ll {
|
function ll {
|
||||||
local ll_output="$(eval $_ll_command $@ $_ls_processor)"
|
local ll_output="$($_ll_command "$@")"
|
||||||
|
|
||||||
|
# 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 "s/ $USER/ $(/bin/cat $HOME/.user_sym)/g" | rejustify_ls_columns)
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$(echo "$ll_output" | wc -l)" -gt "50" ]; then
|
if [ "$(echo "$ll_output" | wc -l)" -gt "50" ]; then
|
||||||
echo -e "\e[33mToo many files to create shortcuts. Running plain ll command...\e[0m"
|
echo -e "\e[33mToo many files to create shortcuts. Running plain ll command...\e[0m"
|
||||||
@@ -116,17 +117,22 @@ 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"
|
||||||
output.lines.each_with_index do |line, i|
|
e = 1
|
||||||
puts line.sub(/^(([^ ]* +){8})/, "\\\1\e[2;37m[\e[0m#{i}\e[2;37m]\e[0m" << (i < 10 ? " " : " "))
|
re = /^(([^ ]* +){8})/
|
||||||
|
output.lines.each do |line|
|
||||||
|
next unless line.match(re)
|
||||||
|
puts line.sub(re, "\\\1\e[2;37m[\e[0m#{e}\e[2;37m]\e[0m" << (e < 10 ? " " : " "))
|
||||||
|
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="$($_ll_sys_command "$@")"
|
||||||
OLDIFS="$IFS"
|
OLDIFS="$IFS"
|
||||||
IFS=$(echo -en "\n\b")
|
IFS=$'\n'
|
||||||
for file in $(eval $_ll_sys_command); do
|
for file in $ll_files; do
|
||||||
export $git_env_char$e="$(eval $_abs_path_command \"$file\")"
|
export $git_env_char$e="$(eval $_abs_path_command \"$file\")"
|
||||||
if [ "${scmbDebug:-}" = "true" ]; then echo "Set \$$git_env_char$e => $file"; fi
|
if [ "${scmbDebug:-}" = "true" ]; then echo "Set \$$git_env_char$e => $file"; fi
|
||||||
let e++
|
let e++
|
||||||
|
|||||||
Reference in New Issue
Block a user