-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·32 lines (25 loc) · 1.28 KB
/
install.sh
File metadata and controls
executable file
·32 lines (25 loc) · 1.28 KB
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
#!/bin/sh
rc_filename=".$(basename $SHELL)rc"
portals_filename=".portals"
portals_alias="alias portals='sed \"/^alias portals/d; /^alias portalize/d; /^alias unportalize/d; s/alias //g; s/=/ /g\" ~/$portals_filename'"
portalize_function_alias="alias portalize='make_portal() { echo alias \$1=\$PWD >> ~/$portals_filename; unset -f make_portal; . ~/$portals_filename }; make_portal'"
unportalize_function_alias="alias unportalize='destroy_portal() { printf \"%s\\\\n\" \"g/alias \$1=/d\" w | ed -s ~/$portals_filename; unalias \$1; unset -f destroy_portal; . ~/$portals_filename }; destroy_portal'"
add_text_to_file_if_not_exists() {
text=$1
file=$2
grep -qxF "$text" $file || echo $text >> $file
unset text file
}
remove_alias() {
# Uses printf with ed
# 'cause the default 'sed -i' is different between Linux and BSD like.
printf "%s\n" "g/alias $1=/d" w | ed -s ~/$portals_filename &>/dev/null
}
add_text_to_file_if_not_exists ". ~/$portals_filename" ~/$rc_filename
remove_alias portals
remove_alias portalize
remove_alias unportalize
echo $portals_alias >> ~/$portals_filename
echo $portalize_function_alias >> ~/$portals_filename
echo $unportalize_function_alias >> ~/$portals_filename
unset portals_alias portalize_function_alias unportalize_function_alias rc_filename portals_filename