manage.sh: fix handling of file names containing spaces
This commit is contained in:
parent
c908641373
commit
f78a0aea73
1 changed files with 21 additions and 19 deletions
40
manage.sh
40
manage.sh
|
|
@ -36,11 +36,11 @@ status_target_begin() {
|
||||||
status_target_end() {
|
status_target_end() {
|
||||||
tilde_expanded_target=${1/\~/$HOME}
|
tilde_expanded_target=${1/\~/$HOME}
|
||||||
|
|
||||||
if [ ! -z $status_source_active ] ; then
|
if [ ! -z "$status_source_active" ] ; then
|
||||||
status_buffer="${bold}${green}*${default} $1${reset}${status_buffer}"
|
status_buffer="${bold}${green}*${default} $1${reset}${status_buffer}"
|
||||||
((status_count_managed=status_count_managed+1))
|
((status_count_managed=status_count_managed+1))
|
||||||
else
|
else
|
||||||
if [ -e $tilde_expanded_target ] ; then
|
if [ -e "$tilde_expanded_target" ] ; then
|
||||||
status_buffer="${yellow}*${default} $1${status_buffer}"
|
status_buffer="${yellow}*${default} $1${status_buffer}"
|
||||||
((status_count_unmanaged=status_count_unmanaged+1))
|
((status_count_unmanaged=status_count_unmanaged+1))
|
||||||
else
|
else
|
||||||
|
|
@ -58,8 +58,10 @@ status_target_end() {
|
||||||
status_target_source() {
|
status_target_source() {
|
||||||
tilde_expanded_target=${1/\~/$HOME}
|
tilde_expanded_target=${1/\~/$HOME}
|
||||||
|
|
||||||
if [ -L $tilde_expanded_target ] ; then
|
if [ -L "$tilde_expanded_target" ] ; then
|
||||||
if [ $(readlink $tilde_expanded_target) = "${PWD}/$2" ] ; then
|
symlink_target=$(readlink "$tilde_expanded_target")
|
||||||
|
|
||||||
|
if [ "$symlink_target" = "${PWD}/$2" ] ; then
|
||||||
status_source_active="y"
|
status_source_active="y"
|
||||||
status_buffer="${status_buffer}${newline} $2"
|
status_buffer="${status_buffer}${newline} $2"
|
||||||
else
|
else
|
||||||
|
|
@ -69,7 +71,7 @@ status_target_source() {
|
||||||
status_buffer="${status_buffer}${newline} ${dim}$2${reset}"
|
status_buffer="${status_buffer}${newline} ${dim}$2${reset}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -e $2 ] ; then
|
if [ ! -e "$2" ] ; then
|
||||||
status_buffer="${status_buffer} ${bold}${yellow}!${reset}"
|
status_buffer="${status_buffer} ${bold}${yellow}!${reset}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
@ -90,10 +92,10 @@ EOF
|
||||||
install_target_source() {
|
install_target_source() {
|
||||||
tilde_expanded_target=${1/\~/$HOME}
|
tilde_expanded_target=${1/\~/$HOME}
|
||||||
|
|
||||||
if [ -z $install_done ] && [ $tilde_expanded_target = $install_target ] ; then
|
if [ -z "$install_done" ] && [ "$tilde_expanded_target" = "$install_target" ] ; then
|
||||||
# if no source is provided, select the first option, otherwise
|
# if no source is provided, select the first option, otherwise
|
||||||
# check for a match
|
# check for a match
|
||||||
if [ -z $install_source ] || [ $install_source = $2 ] ; then
|
if [ -z "$install_source" ] || [ "$install_source" = "$2" ] ; then
|
||||||
echo "${dim}$ ln -sf ${PWD}/$2 $tilde_expanded_target${reset}"
|
echo "${dim}$ ln -sf ${PWD}/$2 $tilde_expanded_target${reset}"
|
||||||
ln -sf "${PWD}/$2" "$tilde_expanded_target"
|
ln -sf "${PWD}/$2" "$tilde_expanded_target"
|
||||||
install_done="y"
|
install_done="y"
|
||||||
|
|
@ -136,7 +138,7 @@ process_target_begin() {
|
||||||
process_target_end() {
|
process_target_end() {
|
||||||
case $mode in
|
case $mode in
|
||||||
("status")
|
("status")
|
||||||
status_target_end $1
|
status_target_end "$1"
|
||||||
;;
|
;;
|
||||||
("install")
|
("install")
|
||||||
true
|
true
|
||||||
|
|
@ -154,10 +156,10 @@ process_target_end() {
|
||||||
process_target_source() {
|
process_target_source() {
|
||||||
case $mode in
|
case $mode in
|
||||||
("status")
|
("status")
|
||||||
status_target_source $1 $2
|
status_target_source "$1" "$2"
|
||||||
;;
|
;;
|
||||||
("install")
|
("install")
|
||||||
install_target_source $1 $2
|
install_target_source "$1" "$2"
|
||||||
;;
|
;;
|
||||||
(*)
|
(*)
|
||||||
echo "Invalid mode: '$mode'"
|
echo "Invalid mode: '$mode'"
|
||||||
|
|
@ -196,7 +198,7 @@ case $1 in
|
||||||
("install")
|
("install")
|
||||||
mode="install"
|
mode="install"
|
||||||
|
|
||||||
if [ -z $2 ] || [ $2 = "--help" ]; then
|
if [ -z "$2" ] || [ "$2" = "--help" ]; then
|
||||||
echo "usage: manage.sh install [target] (source)"
|
echo "usage: manage.sh install [target] (source)"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
@ -233,26 +235,26 @@ target_file=""
|
||||||
while read -r line ; do
|
while read -r line ; do
|
||||||
case $line in
|
case $line in
|
||||||
("-> "*)
|
("-> "*)
|
||||||
if [ -z $target_file ] ; then
|
if [ -z "$target_file" ] ; then
|
||||||
echo "Parsing error: source given without target at line $line_nr"
|
echo "Parsing error: source given without target at line $line_nr"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
source_file=${line#"-> "}
|
source_file=${line#"-> "}
|
||||||
|
|
||||||
process_target_source $target_file $source_file
|
process_target_source "$target_file" "$source_file"
|
||||||
;;
|
;;
|
||||||
("")
|
("")
|
||||||
if [ ! -z $target_file ] ; then
|
if [ ! -z "$target_file" ] ; then
|
||||||
process_target_end $target_file
|
process_target_end "$target_file"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
target_file=""
|
target_file=""
|
||||||
;;
|
;;
|
||||||
(*)
|
(*)
|
||||||
target_file=$line
|
target_file="$line"
|
||||||
|
|
||||||
process_target_begin $target_file
|
process_target_begin "$target_file"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
|
@ -261,8 +263,8 @@ while read -r line ; do
|
||||||
done < "$bindings_file"
|
done < "$bindings_file"
|
||||||
|
|
||||||
# process last item
|
# process last item
|
||||||
if [ ! -z $target_file ] ; then
|
if [ ! -z "$target_file" ] ; then
|
||||||
process_target_end $target_file
|
process_target_end "$target_file"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
process_finished
|
process_finished
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue