1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
#!/usr/bin/env bash
set -e
print=""
if [ "$1" = "-" ]; then
print=1
shift
fi
shell="$1"
if [ -z "$shell" ]; then
shell="$(basename "$SHELL")"
fi
resolve_link() {
$(type -p greadlink readlink | head -1) $1
}
abs_dirname() {
local cwd="$(pwd)"
local path="$1"
while [ -n "$path" ]; do
cd "${path%/*}"
local name="${path##*/}"
path="$(resolve_link "$name" || true)"
done
pwd
cd "$cwd"
}
root="$(abs_dirname "$0")/.."
if [ -z "$print" ]; then
case "$shell" in
bash )
profile='~/.bash_profile'
;;
zsh )
profile='~/.zshenv'
;;
* )
profile='your profile'
;;
esac
{ echo "# Load iron automatically by adding"
echo "# the following to ${profile}:"
echo
echo "eval \"\$(${_BORGO_ROOT}/bin/iron init -)\""
echo
} >&2
exit 1
fi
echo "export PATH=\"\${PATH}:${_BORGO_ROOT}/bin\""
case "$shell" in
bash | zsh )
echo "source \"$root/completions/iron.${shell}\""
;;
esac
commands=(`iron commands --sh`)
IFS="|"
cat <<EOS
_iron_wrapper() {
local command="\$1"
if [ "\$#" -gt 0 ]; then
shift
fi
case "\$command" in
${commands[*]})
eval \`iron "sh-\$command" "\$@"\`;;
*)
command iron "\$command" "\$@";;
esac
}
EOS
# zsh can't pass argument with aliases, but bash can.
# zsh can have functions with the name being only numbers, but bash can't.
# fix both cases here by letting zsh have a function, and bash have its alias.
case "$shell" in
bash )
echo "alias iron=_iron_wrapper"
;;
zsh )
echo "iron=_iron_wrapper"
;;
esac
# This file is part of Iron
# Copyright (c) 2016-2024 Paolo Lulli.
#
# 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
# the Free Software Foundation, version 3.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|