X-Git-Url: https://iankelling.org/git/?p=lnf;a=blobdiff_plain;f=lnf-function;h=daae096c035f51d63500a5f526d79403e260a6ee;hp=61478e7cddab32b3e2e9834c3074e5097ada43e9;hb=0e81e42e5faadf13bb6ef9fe6650f57cbce7422b;hpb=cca94a4f6e8acc20eacb8219b5f910e89b312802 diff --git a/lnf-function b/lnf-function index 61478e7..daae096 100644 --- a/lnf-function +++ b/lnf-function @@ -22,9 +22,13 @@ replacing a file but not a directory. No ln option arguments are supported." shift fi + local reset_extglob=false + ! shopt extglob >/dev/null && reset_extglob=true + shopt -s extglob + local remove x - if type -P dircolors >/dev/null; then + if type -P trash-put >/dev/null; then remove=trash-put else remove="rm -rf" @@ -39,9 +43,9 @@ replacing a file but not a directory. No ln option arguments are supported." elif [[ $# -ge 2 ]]; then if [[ -d ${!#} ]]; then local oldcwd=$PWD - cd ${!#} # last arg - for x in "${@:1:$(($#-1))}"; do # all but last arg - # remove any trailing slashes + cd "${!#}" # last arg + for x in "${@:1:$(( $# - 1 ))}"; do # all but last arg + # remove any trailing slashes, uses extglob x="${x%%+(/)}" # remove any leading directory components x="${x##*/}" @@ -54,5 +58,7 @@ replacing a file but not a directory. No ln option arguments are supported." elif [[ $# -eq 1 ]]; then [[ -e "${1##*/}" || -L "${1##*/}" ]] && $remove "${1##*/}" fi + + $reset_extglob && shopt -u extglob ln -s -- "$@" }