summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorGravatar Caleb Land <caleb@land.fm>2014-02-26 19:14:42 -0500
committerGravatar Mike Burns <mike@mike-burns.com>2014-02-27 16:11:14 +0100
commit95128e051aa0928cbaf97da729b1b9f8df562ed1 (patch)
treeac1323e4318e42167938aa63f8e279a69c7ab348 /bin
parent64c8e0c87e02e3a05631d67c9d3072ca87234711 (diff)
Handle more files with spaces and special chars
Diffstat (limited to 'bin')
-rwxr-xr-xbin/lsrc72
-rwxr-xr-xbin/rcup52
2 files changed, 63 insertions, 61 deletions
diff --git a/bin/lsrc b/bin/lsrc
index d78b0ad..61ba0c4 100755
--- a/bin/lsrc
+++ b/bin/lsrc
@@ -18,14 +18,14 @@ popdir() {
}
build_path() {
- local dest=$1
- local file=$2
+ local dest="$1"
+ local file="$2"
local dotted=$3
if [ $dotted -eq 1 ]; then
- echo $dest/$file
+ echo "$dest/$file"
else
- echo $dest/.$file
+ echo "$dest/.$file"
fi
}
@@ -35,14 +35,14 @@ file_join() {
for file; do
if [ "x$file" != "x." ]; then
if [ "x$result" = "x" ]; then
- result=$file
+ result="$file"
else
result="$result/$file"
fi
fi
done
- echo $result
+ echo "$result"
}
show_dir() {
@@ -54,17 +54,17 @@ show_dir() {
local exclude_file_globs="$6"
local include_file_globs="$7"
local symlink_dirs_file_globs="$8"
- local dest_path=`build_path $dest_dir $dir $dotted`
+ local dest_path=`build_path "$dest_dir" "$dir" $dotted`
$DEBUG "show_dir $1 $2 $3 $4 $5 $6 $7 $8"
$VERBOSE "recurring on $dest_path"
- pushdir $dir
+ pushdir "$dir"
for f in *; do
$DEBUG "handling the file $f"
- next_dir=`file_join $dotfiles_subdir $dir`
- handle_file $f $dest_path $dotfiles_dir $next_dir 1 "$exclude_file_globs" "$include_file_globs" "$symlink_dirs_file_globs"
+ next_dir=`file_join "$dotfiles_subdir" "$dir"`
+ handle_file "$f" "$dest_path" "$dotfiles_dir" "$next_dir" 1 "$exclude_file_globs" "$include_file_globs" "$symlink_dirs_file_globs"
done
popdir
}
@@ -101,35 +101,35 @@ sigil_for() {
}
show_file() {
- local file=$1
- local dest_dir=$2
- local dotfiles_dir=$3
- local dotfiles_subdir=$4
+ local file="$1"
+ local dest_dir="$2"
+ local dotfiles_dir="$3"
+ local dotfiles_subdir="$4"
local dotted=$5
- local symlink_dirs_file_globs=$6
- local dest_file=`build_path $dest_dir $file $dotted`
+ local symlink_dirs_file_globs="$6"
+ local dest_file=`build_path "$dest_dir" "$file" $dotted`
if echo $DEST_STACK | grep -vq ":$dest_file"; then
DEST_STACK="$DEST_STACK:$dest_file"
- src_file=`file_join $dotfiles_subdir $file`
- abs_src_file=`file_join $dotfiles_dir $src_file`
- output=$dest_file:$abs_src_file
+ src_file=`file_join "$dotfiles_subdir" "$file"`
+ abs_src_file=`file_join "$dotfiles_dir" "$src_file"`
+ output="$dest_file:$abs_src_file"
if [ $SHOW_SIGILS -eq 1 ]; then
- sigil=`sigil_for $src_file "$symlink_dirs_file_globs"`
+ sigil=`sigil_for "$src_file" "$symlink_dirs_file_globs"`
output="$output:$sigil"
fi
- $PRINT $output
+ $PRINT "$output"
fi
}
handle_file() {
- local file=$1
- local dest_dir=$2
- local dotfiles_dir=$3
- local dotfiles_subdir=$4
+ local file="$1"
+ local dest_dir="$2"
+ local dotfiles_dir="$3"
+ local dotfiles_subdir="$4"
local dotted=$5
local exclude_file_globs="$6"
local include_file_globs="$7"
@@ -137,16 +137,16 @@ handle_file() {
$DEBUG "handle_file $1 $2 $3 $4 $5 $6 $7 $8"
- if [ ! -e $file ]; then
+ if [ ! -e "$file" ]; then
$VERBOSE "skipping non-existent file $file"
- elif is_excluded $file "$exclude_file_globs" "$include_file_globs"; then
+ elif is_excluded "$file" "$exclude_file_globs" "$include_file_globs"; then
$VERBOSE "skipping excluded file $file"
- elif [ -d $file ] && is_excluded $file "$symlink_dirs_file_globs"; then
- show_file $file $dest_dir $dotfiles_dir $dotfiles_subdir $dotted "$symlink_dirs_file_globs"
- elif [ -d $file ]; then
- show_dir $file $dest_dir $dotfiles_dir $dotfiles_subdir $dotted "$exclude_file_globs" "$include_file_globs" "$symlink_dirs_file_globs"
+ elif [ -d "$file" ] && is_excluded $file "$symlink_dirs_file_globs"; then
+ show_file "$file" "$dest_dir" "$dotfiles_dir" "$dotfiles_subdir" $dotted "$symlink_dirs_file_globs"
+ elif [ -d "$file" ]; then
+ show_dir "$file" "$dest_dir" "$dotfiles_dir" "$dotfiles_subdir" $dotted "$exclude_file_globs" "$include_file_globs" "$symlink_dirs_file_globs"
else
- show_file $file $dest_dir $dotfiles_dir $dotfiles_subdir $dotted
+ show_file "$file" "$dest_dir" "$dotfiles_dir" "$dotfiles_subdir" $dotted
fi
}
@@ -158,7 +158,7 @@ is_metafile() {
}
dotfiles_dir_excludes() {
- local dotfiles_dir=$1
+ local dotfiles_dir="$1"
local excludes="$2"
$DEBUG "dotfiles_dir_excludes $dotfiles_dir"
@@ -183,7 +183,7 @@ dotfiles_dir_excludes() {
}
is_excluded() {
- local file=$1
+ local file="$1"
local exclude_file_globs="$2"
local include_file_globs="$3"
@@ -193,10 +193,10 @@ is_excluded() {
$DEBUG "file: $file"
$DEBUG "exclude_file_glob: $exclude_file_glob"
- case $file in
+ case "$file" in
$exclude_file_glob)
for include_file_glob in $include_file_globs; do
- case $file in
+ case "$file" in
$include_file_glob) return 1;;
esac
done
diff --git a/bin/rcup b/bin/rcup
index 5ba4822..0bf3f35 100755
--- a/bin/rcup
+++ b/bin/rcup
@@ -15,28 +15,28 @@ link_or_copy() {
}
link_file() {
- local src=$1
- local dest=$2
+ local src="$1"
+ local dest="$2"
local sigil=$3
- if [ -h $dest ]; then
- $RM -f $dest
+ if [ -h "$dest" ]; then
+ $RM -f "$dest"
fi
action=`link_or_copy $sigil`
$DEBUG "$action $src $dest"
- $action $src $dest
+ $action "$src" "$dest"
}
replace_file() {
- local src=$1
- local dest=$2
+ local src="$1"
+ local dest="$2"
local sigil=$3
- $DEBUG replace_file $1 $2 $3
-
+ $DEBUG replace_file "$1" "$2" $3
+
$RM -rf $dest
- link_file $src $dest $sigil
+ link_file "$src" "$dest" $sigil
}
is_nested() {
@@ -49,39 +49,39 @@ is_identical() {
}
handle_dir() {
- local dest=$1
+ local dest="$1"
$DEBUG handle_dir $1
- dirname $dest | xargs $MKDIR -p
+ dirname "$dest" | xargs $MKDIR -p
}
handle_file() {
- local src=$1
- local dest=$2
+ local src="$1"
+ local dest="$2"
local sigil=$3
$DEBUG handle_file $1 $2 $3
if [ -e "$dest" ]; then
- if is_identical $src $dest; then
+ if is_identical "$src" "$dest"; then
$VERBOSE "identical $dest"
elif [ $REPLACE_ALL -eq 1 ]; then
- replace_file $src $dest $sigil
+ replace_file "$src" "$dest" $sigil
else
$PROMPT "overwrite ${dest}? [ynaq]"
read overwrite
case $overwrite in
a) REPLACE_ALL=1
- replace_file $src $dest $sigil
+ replace_file "$src" "$dest" $sigil
;;
- y) replace_file $src $dest $sigil ;;
+ y) replace_file "$src" "$dest" $sigil ;;
q) exit 1 ;;
*) $VERBOSE "skipping $dest" ;;
esac
fi
else
- link_file $src $dest $sigil
+ link_file "$src" "$dest" $sigil
fi
}
@@ -165,20 +165,22 @@ handle_command_line $*
run_hooks pre up
+saved_ifs=$IFS
+IFS='
+'
for dest_and_src in `lsrc $LS_ARGS`; do
- saved_ifs=$IFS
IFS=:
set $dest_and_src
IFS=$saved_ifs
- dest=$1
- src=$2
+ dest="$1"
+ src="$2"
sigil=$3
- if is_nested $dest; then
- handle_dir $dest
+ if is_nested "$dest"; then
+ handle_dir "$dest"
fi
- handle_file $src $dest $sigil
+ handle_file "$src" "$dest" $sigil
done
run_hooks post up