X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=lib.sh;h=ba4e658f978d4033e732b88839577341729e6209;hb=12209c39f81df94c1b55ac84f49f802effe484bb;hp=474f638c42c8fc858418656ca59ad73e9adab8da;hpb=0d6b1deba13390ed289d4c933e0a05da7d031e5e;p=config%2Fdotfiles.git diff --git a/lib.sh b/lib.sh index 474f638..ba4e658 100644 --- a/lib.sh +++ b/lib.sh @@ -41,7 +41,7 @@ installed_path() { # Walk PATH. for directory in $PATH; do if test -x "$directory/$1"; then - echo "$directory/$1" + printf '%s\n' "$directory/$1" return 0 fi done @@ -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 } @@ -143,30 +143,31 @@ link() { # Get all necessary paths. pwd=`pwd` - base=`echo "$2" | sed "s|\~|$HOME|"` # expand ~, some sh don't do it + base=`printf '%s' "$2" | sed "s|\~|$HOME|"` # expand ~, some sh don't do it base=`dirname "$base"` - source=`echo "$pwd/$1" | sed "s|$base/||"` + source=`printf '%s' "$pwd/$1" | sed "s|$base/||"` 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 - echo "link(): target '$target' exists already and is no symbolic link!" >&2 + printf "link(): target '%s' exists already and is no symbolic link!" \ + "$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 - echo "link(): source '$source' doesn't exist!" >&2 + printf "link(): source '%s' doesn't exist!" "$source" >&2 exit 1 fi # Create the new symbolic link; remove the old one if necessary. - echo "link(): linking '$source' to '$target'" + printf "link(): linking '%s' to '%s'\n" "$source" "$target" rm -f "$target" ln -s "$source" "$target" @@ -177,7 +178,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). @@ -203,7 +204,8 @@ generate() { echo '# WARNING! DO NOT EDIT THIS FILE! #' >>"$file" echo '###################################' >>"$file" echo >>"$file" - echo "# It was generated from $file$extension on `date`." >>"$file" + printf "# It was generated from '%s' on %s.\n" \ + "$file$extension" "`date`" >>"$file" echo >>"$file" file_tmp="$file"