2 # Copyright (C) 2014 Ian Kelling
3 # This program is under GPL v. 3 or later, see <http://www.gnu.org/licenses/>
6 local help="lnf [--help] [-T] LN_ARGUMENT...
7 Create symlinks conveniently and forcefully.
9 Remove existing file/links using trash-put or rm -rf if it is not available.
10 Create directory if needed. Small change to ln argument semantics: for 2 arguments,
11 the second argument is a directory unless -T is passed. This removes ambiguity of
12 replacing a file but not a directory. No ln option arguments are supported."
14 if [[ $1 == --help ||
$# -eq 0 ]]; then
20 if [[ $1 == -T ]]; then
27 if type -P dircolors
>/dev
/null
; then
33 if $nodir && [[ $# -eq 2 ]]; then
34 if [[ -e "$2" ||
-L "$2" ]]; then
36 elif [[ ! -d "$2/.." ]]; then
39 elif [[ $# -ge 2 ]]; then
40 if [[ -d ${!#} ]]; then
43 for x
in "${@:1:$(( $# - 1 ))}"; do # all but last arg
44 # remove any trailing slashes
46 # remove any leading directory components
48 [[ -e "$x" ||
-L "$x" ]] && $remove "$x"
54 elif [[ $# -eq 1 ]]; then
55 [[ -e "${1##*/}" || -L "${1##*/}" ]] && $remove "${1##*/}"