-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfunctions.sh
executable file
Β·120 lines (100 loc) Β· 2.47 KB
/
functions.sh
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
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env bash
running_macos() {
[ "$(uname)" == Darwin ]
return $?
}
running_codespaces() {
[ "$CODESPACES" = true ]
return $?
}
command_available() {
which "$1" > /dev/null 2>&1
}
fzf_available() {
command_available fzf
}
fish_available() {
command_available fish
}
brew_available() {
command_available brew
}
load_brew_shellenv() {
if test -x /opt/homebrew/bin/brew; then
brew=/opt/homebrew/bin/brew
elif test -x /usr/local/bin/brew; then
brew=/usr/local/bin/brew
fi
if test -n "${brew}"; then
eval "$($brew shellenv)"
fi
}
vscode_command() {
if command_available code-insiders; then
code="code-insiders"
elif command_available code; then
code="code"
fi
echo "$code"
}
find_targets() {
local directory="$1"
# only get the top level files/directories
# also exclude the directory itself
find "$directory" -mindepth 1 -maxdepth 1
}
link_directory_contents() {
local directory="$1"
for linkable in $(find_targets "${directory}"); do
if [[ "$linkable" = "config" ]] || [[ "${linkable}" = "home" ]]; then
continue
fi
if [ "$directory" = "home" ]; then
target="$HOME/$(basename "$linkable")"
elif [ "${directory}" = "config" ]; then
target="$HOME/.config/$(basename "$linkable")"
else
echo "don't know where to put ${directory} links"
return 1
fi
link "$linkable" "$target"
done
}
link() {
local linkable="$1"
local target="$2"
local display_target="${target/$HOME/~}"
if [ ! -L "$target" ]; then
echo "π $display_target β linking from $linkable"
ln -Ff -s "$DIR/$linkable" "$target"
elif [ "$(readlink "$target")" != "${DIR}/${linkable}" ]; then
echo "π $display_target β already linked to $(readlink "${target}")"
read -p "Overwrite it to link to ${DIR}/${linkable}? " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "π $display_target β linking from $linkable"
ln -Ff -s "$DIR/$linkable" "$target"
fi
else
echo "π $display_target β already linked"
fi
}
brew_bundle() {
echo "π» running brew bundle"
cat Brewfile "Brewfile.${DOTPICKLES_ROLE}" 2> /dev/null | brew bundle --file=- | sed 's/^/ β /'
echo
}
vim_plugins() {
echo "β¨οΈοΈ configuring vim"
vim +PlugInstall +qall
echo
}
# make sure op is logged in
op_ensure_signed_in() {
if ! which op > /dev/null 2> /dev/null; then
brew install 1password-cli
fi
if ! op whoami > /dev/null 2>&1; then
op signin
fi
}