X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=lib.sh;h=70be68df0433531e27c5f7ab58e99bf8350a305e;hb=00b4c91969f0ee1fd7ea4e87a0b0e1ab9407c87c;hp=c55cb0acd44a218825c0242b32285e40494a9199;hpb=23d085143315d7cbce8c0be18822e96ca5d40889;p=config%2Fdotfiles.git diff --git a/lib.sh b/lib.sh index c55cb0a..70be68d 100644 --- a/lib.sh +++ b/lib.sh @@ -2,7 +2,7 @@ # # Their setup.sh script sources this file. -# Copyright (C) 2009-2013 Simon Ruderich +# Copyright (C) 2009-2014 Simon Ruderich # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -53,7 +53,7 @@ installed_path() { # Usage: cmd_i ... # # Run with all arguments (including the last file) and write the result -# to the temporary file .tmp and then renamed that file to . This +# to the temporary file .tmp and then rename that file to . This # can't be done in-place (e.g. cmd file) because it truncates the file. cmd_i() { # Get last argument. @@ -128,7 +128,7 @@ os() { elif test x`uname` = xFreeBSD; then echo freebsd else - echo unsupported OS! >&2 + echo 'unsupported OS!' >&2 return 1 fi } @@ -149,20 +149,19 @@ link() { target=`basename "$2"` # Go to the directory where the link is going to be created. - cd "$base" + cd "$base" || return 1 # Abort if the target file exists and is no symbolic link. Prevents # overwriting real files. - if ( test -f "$target" && test ! -h "$target" ) || \ - ( test -s "$target" && test ! -h "$target" ); then - printf "link(): target '%s' exists already and is no symbolic link!" \ + if test -e "$target" && test ! -h "$target"; then + printf "link(): target '%s' exists already and is no symbolic link!\n" \ "$target" >&2 exit 1 fi - # Make sure the source exists (is file, directory or link). - if test ! -f "$source" && test ! -d "$source" && test ! -h "$source"; then - printf "link(): source '%s' doesn't exist!" "$source" >&2 + # Make sure the source exists. + if test ! -e "$source"; then + printf "link(): source '%s' doesn't exist!\n" "$source" >&2 exit 1 fi @@ -178,7 +177,7 @@ link() { # Generate a file from a source file using a given command. A warning not to # edit it is automatically added to the created file. # -# Usage: generated() +# Usage: generate # # If an empty extension is provided, the file is modified in-place (through a # temporary file).