Skip to content

Commit 44bb8d5

Browse files
tools init
1 parent caaf00e commit 44bb8d5

21 files changed

+192
-160
lines changed

.zshrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# .zshrc is a symlink to .zshrc in this repo wherever it is cloned on disk
22
export DOT_FILES_PATH=$(dirname $(readlink ~/.zshrc))
3+
export DOT_DOT_PATH="${DOT_FILES_PATH}/dot"
4+
export DOT_TOOLS_PATH="${DOT_FILES_PATH}/tools"
35

46
source "${DOT_FILES_PATH}/dot/load.sh"
57

@@ -22,9 +24,10 @@ PROMPT='%(?.%F{green}√.%F{red}?%?)%f %B%F{250}%1~%f%b %(!.#.$) '
2224
dot_load
2325
dot_help
2426

25-
"${DOT_FILES_PATH}/dot/tools.sh" "init"
27+
# "${DOT_FILES_PATH}/dot/tools.sh" "init"
2628
# dot_load_tools
2729
# echo
30+
dot_tools "init"
2831

2932
# codespaces automatically takes you into that repo.
3033
# else, lets start in the root of our workspaces directory (the w alias)

dot/load.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/bin/zsh
21

32
# call to reload
43
function dot_load() {
@@ -17,8 +16,6 @@ function dot_load() {
1716

1817
[ ! -d "${DOT_FILES_PATH}" ] && >&2 echo "${DOT_FILES_PATH} missing" && return 1
1918

20-
# source "${DOT_FILES_PATH}/common/env.sh"
21-
2219
# load public scripts
2320
for filename in ${DOT_FILES_PATH}/rc/*.sh; do
2421
source "${filename}"
@@ -29,4 +26,8 @@ function dot_load() {
2926
if [ -f "${priv_sec}" ]; then
3027
source "${priv_sec}"
3128
fi
29+
30+
# echo "sourcing ${DOT_FILES_PATH}/dot/tools.sh"
31+
# source "${DOT_FILES_PATH}/dot/tools.sh"
32+
# echo "done"
3233
}

dot/tools.sh

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,60 +3,44 @@
33
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
44
. $SCRIPT_DIR/common.sh
55

6-
toolsDir() {
7-
pushd "${SCRIPT_DIR}/../tools"
8-
}
9-
106
assert() {
11-
if [ ! -f "${1}.sh" ]; then
7+
if [ ! -f "${DOT_TOOLS_PATH}/${1}.sh" ]; then
128
echo "Tool not found: $1"
139
exit 1
14-
fi
10+
fi
1511
}
1612

1713
info() {
18-
toolsDir
1914
assert "$1"
20-
"./${1}.sh" "info"
15+
"${DOT_TOOLS_PATH}/${1}.sh" "info"
2116
}
2217

23-
init() {
24-
toolsDir
25-
26-
for file in ./*.sh; do
27-
file_name="$(basename -s .sh $file)"
28-
# echo "./${file_name}.sh init"
29-
"./${file_name}.sh" "init"
30-
done
31-
}
18+
install() {
19+
assert "$1"
20+
"${DOT_TOOLS_PATH}/${1}.sh" "install"
21+
}
3222

3323
ls() {
34-
toolsDir
35-
36-
count=$(find . -name "*.sh" | wc -l)
24+
count=$(find "${DOT_TOOLS_PATH}" -name "*.sh" | wc -l)
3725
if [ $count -eq 0 ]; then return; fi
3826

3927
echo
4028
dot_section "Tools"
4129
echo
4230
# echo
43-
for file in ./*.sh; do
31+
for file in ${DOT_TOOLS_PATH}/*.sh; do
4432
file_name="$(basename -s .sh $file)"
4533
cprint " 🔹 $file_name\n" "white" "intense";
4634
done
4735

4836
echo
4937
echo
50-
dot_message "tool info <name>" "tool info like version path"
38+
dot_message "tools info <name>" "tool info like version path"
5139
echo
52-
dot_message "tool install <name>" "install the tool"
40+
dot_message "tools install <name>" "install the tool"
5341
echo
54-
dot_message "tool whoami <name>" "logged in as for the the tool"
42+
dot_message "tools whoami <name>" "logged in as for the the tool"
5543
echo
5644
}
5745

58-
if [ "$#" -eq 0 ]; then
59-
ls
60-
else
61-
"$@"
62-
fi
46+
"$@"

rc/alias.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ alias c="tput reset"
55

66
# Reload the shell (i.e. invoke as a login shell)
77
alias reload="dot_reload"
8-
alias tools="${DOT_FILES_PATH}/dot/tools.sh $@"
8+
alias tools="dot_tools $@"
99
alias me="dot_tool_whoami"
1010
alias setsec="dot_set_secret"
1111
alias getsec="dot_get_secret"

rc/tools.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
3+
dot_tools_info() {
4+
"${DOT_DOT_PATH}/tools.sh" "info" "$1"
5+
}
6+
7+
dot_tools_install() {
8+
"${DOT_DOT_PATH}/tools.sh" "install" "$1"
9+
}
10+
11+
dot_tools_init() {
12+
for file in ${DOT_TOOLS_PATH}/*_init; do
13+
file_name="$(basename $file)"
14+
source "${DOT_TOOLS_PATH}/${file_name}"
15+
done
16+
}
17+
18+
dot_tools_ls() {
19+
"${DOT_DOT_PATH}/tools.sh" "ls"
20+
}
21+
22+
dot_tools() {
23+
cmd=$1
24+
if [ "$cmd" ]; then
25+
shift
26+
"dot_tools_$cmd" "$@"
27+
28+
# reload tools env and paths
29+
dot_tools_init
30+
else
31+
dot_tools_ls
32+
fi
33+
}

tools/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# tools
2+
3+
Create scripts per tool to manage
4+
5+
## <tool>_init
6+
7+
Sourced into the current zshell. Set up paths and any variables needed.
8+
9+
## <tool>.sh
10+
11+
Functions to provide tool info (versions, where installed, shell completions etc) and username logged in as.
12+
13+
These are not sourced into the shell. They are executed in a new shell
14+
15+
```shell
16+
info() {
17+
# echo verions, where installed, etc
18+
echo
19+
echo toolname --version
20+
which toolname
21+
}
22+
23+
whoami() {
24+
# echo who you are logged in as
25+
return
26+
}
27+
28+
install() {
29+
# scripts to install on macos or linux
30+
return
31+
}
32+
```
33+

tools/brew.sh

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,11 @@
33
# install brew if not installed
44
# we can install most other things using brew afterwards
55

6-
init() {
7-
return
8-
}
9-
10-
function dot_brew_version() {
6+
info() {
117
echo.
128
brew --version
139
}
1410

15-
function dot_brew_whoami() {
16-
return
17-
}
18-
19-
info() {
20-
return
21-
}
22-
2311
whoami() {
2412
return
2513
}

tools/deno.sh

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22

33
denoPath=`which deno`
44

5-
init() {
6-
if [ -f ${denoPath} ]; then
7-
echo "TODO: fix"
8-
#deno completions zsh > ~/.zsh/_deno
9-
fi
10-
}
11-
125
info() {
136
if [ -f ${denoPath} ]; then
14-
which deno
7+
echo
158
deno --version
9+
which deno
10+
echo
11+
else
12+
echo "Not installed"
1613
fi
1714
}
1815

tools/deno_init

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# TODO: fix
2+
3+
denoPath=`which deno`
4+
5+
if [ -f ${denoPath} ]; then
6+
# TODO: fix
7+
# deno completions zsh > ~/.zsh/_deno
8+
fi

tools/gcloud.sh

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
11
#!/bin/zsh -e
22

3-
gc_version="385.0.0"
4-
gc_dlPath="${HOME}/Downloads/cloud-${gc_version}"
5-
6-
init() {
7-
# The next line updates PATH for the Google Cloud SDK.
8-
if [ -f "${gc_dlPath}/google-cloud-sdk/path.zsh.inc" ]; then . "${gc_dlPath}/google-cloud-sdk/path.zsh.inc"; fi
9-
10-
# The next line enables shell command completion for gcloud.
11-
if [ -f "${gc_dlPath}/google-cloud-sdk/completion.zsh.inc" ]; then . "${gc_dlPath}/google-cloud-sdk/completion.zsh.inc"; fi
12-
}
13-
143
info() {
15-
init
16-
174
gcloudPath=`which gcloud`
185
# gcloud version --format=json
196
if [ -f ${gcloudPath} ]; then
@@ -24,8 +11,12 @@ info() {
2411
}
2512

2613
whoami() {
14+
gcloudPath=`which gcloud`
15+
2716
if [ -f ${gcloudPath} ]; then
2817
gcloud config get-value account
18+
else
19+
echo "not installed"
2920
fi
3021
}
3122

@@ -35,15 +26,25 @@ install() {
3526
file="google-cloud-cli-${gc_version}-darwin-x86_64.tar.gz"
3627
link="https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/"
3728

38-
echo "Downloading to ${gc_dlPath} ..."
39-
mkdir -p "${gc_dlPath}"
40-
pushd "${gc_dlPath}"
41-
curl -L "$link""$file" | tar xz
29+
install_script="${TOOL_GCLOUD_PATH}/google-cloud-sdk/install.sh"
30+
echo "${install_script}"
31+
32+
if [ ! -f "${install_script}" ]; then
33+
rm -rf "${TOOL_GCLOUD_PATH}"
34+
echo "Downloading to ${TOOL_GCLOUD_PATH} ..."
35+
mkdir -p "${TOOL_GCLOUD_PATH}"
36+
pushd "${TOOL_GCLOUD_PATH}"
37+
curl -L "$link""$file" | tar xz
38+
else
39+
pushd "${TOOL_GCLOUD_PATH}"
40+
echo "${install_script} exists. Skipping download"
41+
fi
42+
4243
CLOUDSDK_CORE_DISABLE_PROMPTS=1 ./google-cloud-sdk/install.sh
4344

4445
elif [ "$(uname)" = "Linux" ]; then
4546
return
46-
fi
47+
fi
4748
}
4849

4950
"$@"

tools/gcloud_init

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
export TOOL_GCLOUD_VERSION="385.0.0"
3+
export TOOL_GCLOUD_PATH="${HOME}/Downloads/cloud-${TOOL_GCLOUD_VERSION}"
4+
5+
# The next line updates PATH for the Google Cloud SDK.
6+
if [ -f "${TOOL_GCLOUD_PATH}/google-cloud-sdk/path.zsh.inc" ]; then . "${TOOL_GCLOUD_PATH}/google-cloud-sdk/path.zsh.inc"; fi
7+
8+
# The next line enables shell command completion for gcloud.
9+
if [ -f "${TOOL_GCLOUD_PATH}/google-cloud-sdk/completion.zsh.inc" ]; then . "${TOOL_GCLOUD_PATH}/google-cloud-sdk/completion.zsh.inc"; fi

tools/go.sh

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,7 @@
11
#!/bin/bash -e
22

3-
go_path="/usr/local/go/bin"
4-
go_bin="$HOME/go/bin"
5-
6-
init() {
7-
if [ -d ${go_path} ]; then
8-
if [ ! -x "$(command -v go)" ]; then
9-
echo "Adding go to PATH"
10-
export PATH=$PATH:${go_path}
11-
fi
12-
13-
if [ -d ${go_bin} ]; then
14-
export PATH=$PATH:${go_bin}
15-
fi
16-
fi
17-
}
18-
193
info() {
20-
if [ -d ${go_path} ]; then
4+
if [ -d ${TOOL_GO_PATH} ]; then
215
which go
226
go version
237
else

tools/go_init

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
export TOOL_GO_PATH="/usr/local/go/bin"
3+
export TOOL_GO_BIN="$HOME/go/bin"
4+
5+
init() {
6+
if [ -d ${TOOL_GO_PATH} ]; then
7+
if [ ! -x "$(command -v go)" ]; then
8+
echo "Adding go to PATH"
9+
export PATH=$PATH:${TOOL_GO_PATH}
10+
fi
11+
12+
if [ -d ${TOOL_GO_BIN} ]; then
13+
export PATH=$PATH:${TOOL_GO_BIN}
14+
fi
15+
fi
16+
}

tools/mongo.sh

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,8 @@
11
#!/bin/bash -e
22

3-
mongodPath=`which mongod`
4-
5-
init() {
6-
if [ -f ${mongodPath} ]; then
7-
dbPath="${HOME}/data/mongodb";
8-
if [ -d "" ]; then
9-
alias mongod="ulimit -n 1024 && sudo mongod --dbpath ${HOME}/data/mongodb"
10-
fi
11-
fi
12-
}
13-
14-
function dot_mongod_version() {
15-
if [ -f ${mongodPath} ]; then
16-
printToolInfo 'mongod' mongodPath
17-
fi
18-
}
19-
203
info() {
21-
return
4+
which mongod
5+
mongod --version
226
}
237

248
whoami() {

0 commit comments

Comments
 (0)