X-Git-Url: https://ruderich.org/simon/gitweb/?p=config%2Fdotfiles.git;a=blobdiff_plain;f=lib.sh;h=5abd27898400e44bbaed2c14ec4a45ce80b8f480;hp=7b76a7cab66b08cad1d639f0c059fae2dc637798;hb=8348ecd5e6759f9551fac0431a45c3bdffc36956;hpb=f2ae0a2fdd20981164c1a10b0be4c354234610b0 diff --git a/lib.sh b/lib.sh index 7b76a7c..5abd278 100644 --- a/lib.sh +++ b/lib.sh @@ -50,21 +50,29 @@ installed_path() { ) } -# Usage: sed_i ... +# Usage: cmd_i ... # -# Uses .tmp as temporary file. sed -i is not compatible due to different -# implementations. -sed_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 +# can't be done in-place (e.g. cmd file) because it truncates the file. +cmd_i() { # Get last argument. last= for x; do last="$x" done - sed "$@" >"$last".tmp + "$@" >"$last".tmp mv "$last".tmp "$last" } +# Usage: sed_i ... +# +# sed -i is not compatible due to different implementations. See cmd_i. +sed_i() { + cmd_i sed "$@" +} + # Print the current OS. The following OS are supported at the moment: # - Debian (debian) # - Gentoo (gentoo)