Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions .github/workflows/bats.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ name: CI

# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the master branch
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ master ]
branches: [ main ]
pull_request:
branches: [ master ]
branches: [ main ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand All @@ -27,4 +27,11 @@ jobs:
- uses: actions/setup-node@v1
- run: npm install -g bats
- run: mkdir -p $HOME/.local/bin
- run: bats tests
- run: bats tests
shellcheck:
name: Shellcheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@master
4 changes: 3 additions & 1 deletion 1password.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

1password_install_cli() {
[[ "$(uname)" == "Darwin" ]] && brew install 1password-cli && libsh__exit_with_message "Installed" "1password-cli"
[[ "$(uname)" == "Linux" ]] && export LIBSH_OSLINUX=t
[[ "${LIBSH_OSLINUX}" == "t" ]] && wget -O /tmp/op.zip https://cache.agilebits.com/dist/1P/op/pkg/v1.8.0/op_linux_386_v1.8.0.zip && mkdir -p $HOME/.local/bin && unzip /tmp/op.zip -d $HOME/.local/bin
}
}
44 changes: 29 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,48 @@

boot your sh

## install
## install summary

List of steps for installing libsh:

* git clone https://github.com/aaronaddleman/libsh
* add libsh to your init files
* add libsh to your init files:
* .zshrc
* .zshenv
* cp .libshrc_example to $HOME/.libshrc
* (optional) create $HOME/.sh.d/ and any filename.sh or filename.env.sh file will be loaded

## install (copy+paste)

```
# .zshrc
source $HOME/src/libsh/libsh.sh "fn"
# .zshenv
source $HOME/src/libsh/libsh.sh "env"
echo "source $(pwd)/libsh.sh \"fn\"" >> $HOME/.zshrc
echo "source $(pwd)/libsh.sh \"env\"" >> $HOME/.zshenv
cp .libshrc_example $HOME/.libshrc
```

* add .libshrc from $HOME/src/libsh/.libshrc

This file selects which modules are loaded. This file
contains lots of comments about each option.
## install (manual)

```
cp $HOME/src/libsh/.libshrc_example $HOME/.libshrc
source $LIBSH_REPO_PATH/libsh.sh \"fn\"" >> $HOME/.zshrc
source $LIBSH_REPO_PATH/libsh.sh \"env\"" >> $HOME/.zshenv
cp .libshrc_example $HOME/.libshrc
```

* (optional) create a `$HOME/.sh.d/yourown.env.sh` or `$HOME/.sh.d/yourown.sh`.
## description of files

`libsh.sh`

- This is the main file that loads libsh files and environment variables.

`.libshrc_example`

- Example configuration file for settings to be used in your shell and libsh.

LIBSH will load all `yourown.env.sh` or `yourown.sh` files from $HOME/.sh.d
`$HOME/.config/libsh/hc_vaults.json`

## config files
- Configuration file for multiple HashiCorp Vault servers

### hc vaults
## hc vaults file

Creating a file like the following allows you to select vaults

Expand Down
1 change: 1 addition & 0 deletions aws.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env bash

aws_validate_env() {
if command -v aws > /dev/null; then
Expand Down
8 changes: 5 additions & 3 deletions bash.env.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/usr/bin/env bash

# load any additional settings
#[ -d $HOME/.bash.d ] && ls $HOME/.bash.d/*.env.sh 1> /dev/null 2>&1

#[ "$?" == "0" ] && source $HOME/.bash.d/*.env.sh

local num_of_env_sh=$(find $HOME/.bash.d -maxdepth 1 -type f -name '*.env.sh' | wc -l)
libsh__debug "INFO Found ${num_of_env_sh} files matching $HOME/.bash.d/*.env.sh ."
[ "${num_of_env_sh}" -gt 0 ] && source $HOME/.bash.d/*.env.sh
libsh__num_of_env_sh=$(find $HOME/.bash.d -maxdepth 1 -type f -name '*.env.sh' | wc -l)
libsh__debug "INFO Found ${libsh__num_of_env_sh} files matching $HOME/.bash.d/*.env.sh ."
[ "${libsh__num_of_env_sh}" -gt 0 ] && source $HOME/.bash.d/*.env.sh
1 change: 1 addition & 0 deletions brew.env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[[ -f /opt/homebrew/bin/brew ]] && eval "$(/opt/homebrew/bin/brew shellenv)"
4 changes: 3 additions & 1 deletion clojure.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

clojure_install() {
brew install clojure/tools/clojure
}
}
2 changes: 2 additions & 0 deletions custom.env.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

# load any additional settings
{
local dirlist=($(ls $HOME/.sh.d/*.env.sh))
Expand Down
2 changes: 2 additions & 0 deletions custom.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

# load any additional settings
{
local dirlist=($(ls $HOME/.sh.d/*.fn.sh))
Expand Down
2 changes: 2 additions & 0 deletions figlet.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

figlet_install_fonts() {
local help=$(cat <<HELP
## figlet_install_fonts
Expand Down
2 changes: 2 additions & 0 deletions git.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

#
# set git auto correct
#
Expand Down
4 changes: 3 additions & 1 deletion go.env.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

# GOENV
[ -d $HOME/.goenv ] && export GOENV_ROOT="$HOME/.goenv"
[ -d $HOME/.goenv ] && libsh__add_path "pre" "$GOENV_ROOT/bin"
Expand All @@ -10,7 +12,7 @@
# GOPATH
## this will not conflict with goenv because the destination for
## for goenv is $HOME/go/VER/bin
[ -d $HOME/go -a ! -d $HOME/.goenv ] && export GOPATH="$HOME/go" || libsh__debug "x..could not find $HOME/go"
[ -d $HOME/go && ! -d $HOME/.goenv ] && export GOPATH="$HOME/go" || libsh__debug "x..could not find $HOME/go"
[ -d $HOME/go/bin ] && libsh__add_path "post" "$HOME/go/bin"

# GOROOT
Expand Down
2 changes: 2 additions & 0 deletions go.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

# if you have .goenv installed, init
#[ -d $HOME/.goenv ] && export GOENV_ROOT="$HOME/.goenv"
#[ -d $HOME/.goenv ] && libsh__add_path "pre" "$GOENV_ROOT/bin"
Expand Down
4 changes: 3 additions & 1 deletion haskell.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env bash

haskell_install_stack() {
# install the stack so you can run haskell
curl -sSL https://get.haskellstack.org/ | sh
}
}
2 changes: 2 additions & 0 deletions jupyter.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

jupyter_labs_docker_base() {
local help=$(cat <<HELP
## jupyter_labs_docker_base
Expand Down
2 changes: 2 additions & 0 deletions jupyterlabs_boot.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

# do things before the notebook is created
sudo apt update && apt install -y curl net-tools zsh git unzip
# set zsh for the user
Expand Down
1 change: 1 addition & 0 deletions libsh.env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#!/usr/bin/env bash
56 changes: 32 additions & 24 deletions libsh.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

#
# LIBSH
#
Expand All @@ -19,41 +21,47 @@
#
# Find out where this file lives and call it home
#
if [ -z $LIBSH_HOME ]; then
if [ -z "$LIBSH_HOME" ]; then
case $SHELL in
*zsh)
export LIBSH_HOME=${0:a:h}
export LIBSH_DEBUG_LOGFILE=$LIBSH_HOME/debug.log
LIBSH_HOME=${0:a:h}
export LIBSH_HOME
LIBSH_DEBUG_LOGFILE=$LIBSH_HOME/debug.log
export LIBSH_DEBUG_LOGFILE
;;
*bash)
export LIBSH_HOME=$(dirname $BASH_SOURCE[@])
export LIBSH_DEBUG_LOGFILE=$LIBSH_HOME/debug.log
LIBSH_HOME=$(dirname "${BASH_SOURCE[@]}")
export LIBSH_HOME
LIBSH_DEBUG_LOGFILE=$LIBSH_HOME/debug.log
export LIBSH_DEBUG_LOGFILE
;;
*ash)
export LIBSH_HOME=$(dirname $BASH_SOURCE[@])
export LIBSH_DEBUG_LOGFILE=$LIBSH_HOME/debug.log
LIBSH_HOME=$(dirname "${BASH_SOURCE[@]}")
export LIBSH_HOME
LIBSH_DEBUG_LOGFILE=$LIBSH_HOME/debug.log
export LIBSH_DEBUG_LOGFILE
;;
*)
echo "Failed. Shell of \"$SHELL\" not supported" && kill -INT $$
esac

[ -n $LIBSH_HOME ] && export LIBSH_DEBUG_LOGFILE=$LIBSH_HOME/debug.log
[ -z $LIBSH_HOME ] && echo "Could not set LIBSH_HOME." && kill -INT $$
[[ -n "$LIBSH_HOME" ]] && export LIBSH_DEBUG_LOGFILE=$LIBSH_HOME/debug.log
[[ -z "$LIBSH_HOME" ]] && echo "Could not set LIBSH_HOME." && kill -INT $$
fi


#
# Load libsh_utils.sh
#
[ -n "${LIBSH_HOME}" ] && source $LIBSH_HOME/libsh_utils.sh
[ -n "${LIBSH_HOME}" ] && source "$LIBSH_HOME"/libsh_utils.sh

#
# define custom Functions and default Functions
#
source $LIBSH_HOME/.libshrc.sh && libsh__debug "loaded $LIBSH_HOME/.libshrc.sh"
source "$LIBSH_HOME"/.libshrc.sh && libsh__debug "loaded $LIBSH_HOME/.libshrc.sh"
# if custom libshrc exists, load that
[[ -f "$HOME/.libshrc" ]] && source $HOME/.libshrc && libsh__debug "loaded $HOME/.libshrc"
[[ -f "$HOME/.libshrc.sh" ]] && source $HOME/.libshrc.sh && libsh__debug "loaded $HOME/.libshrc.sh"
[[ -f "$HOME/.libshrc" ]] && source "$HOME"/.libshrc && libsh__debug "loaded $HOME/.libshrc"
[[ -f "$HOME/.libshrc.sh" ]] && source "$HOME"/.libshrc.sh && libsh__debug "loaded $HOME/.libshrc.sh"

libsh_fn=("${libsh_fn_custom[@]}" "${libsh_fn_defaults[@]}")
libsh__debug "fn custom -> ${libsh_fn_custom[*]}"
Expand All @@ -67,16 +75,16 @@ libsh__load() {

# when in debug mode,
# remove log file if it exists
[ -n $LIBSH_DEBUG ] && \
[ -f $LIBSH_DEBUG_LOGFILE ] && \
[ $(wc -l $LIBSH_DEBUG_LOGFILE | awk '{print $1}') -gt 1000 ] && \
rm $LIBSH_DEBUG_LOGFILE
[ -n "$LIBSH_DEBUG" ] && \
[ -f "$LIBSH_DEBUG_LOGFILE" ] && \
[ "$(wc -l "$LIBSH_DEBUG_LOGFILE" | awk '{print $1}')" -gt 1000 ] && \
rm "$LIBSH_DEBUG_LOGFILE"

# start of libsh fn and env for-loop
if [ ${#libsh_fn[@]} ]; then
[[ "${mode}" == "env" ]] && libsh__debug "\n\n---ENV-$(date)--"
[[ "${mode}" == "fn" ]] && libsh__debug "\n\n---FN-$(date)--"
for fn in ${libsh_fn[@]}
for fn in "${libsh_fn[@]}"
do
### FN
# debug and show what we load for ${FN}.sh
Expand All @@ -85,8 +93,8 @@ libsh__load() {
local fn_varname="LIBSH_status_fn_${fn}"
# load the FNs
[[ "${mode}" == "fn" ]] && \
[ -f ${LIBSH_HOME}/${fn}.sh ] && \
source ${LIBSH_HOME}/${fn}.sh && \
[ -f "${LIBSH_HOME}"/"${fn}".sh ] && \
source "${LIBSH_HOME}"/"${fn}".sh && \
printf -v "$fn_varname" '%s' "loaded" && \
libsh__debug "FN Loaded '${LIBSH_HOME}/${fn}.sh'"

Expand All @@ -97,8 +105,8 @@ libsh__load() {
local env_varname="LIBSH_status_env_${fn}"
# load the FNs envs
[[ "${mode}" == "env" ]] && \
[ -f ${LIBSH_HOME}/${fn}.env.sh ] && \
source ${LIBSH_HOME}/${fn}.env.sh && \
[ -f "${LIBSH_HOME}"/"${fn}".env.sh ] && \
source "${LIBSH_HOME}"/"${fn}".env.sh && \
printf -v "$env_varname" '%s' "loaded" && \
libsh__debug "ENV Loading '${LIBSH_HOME}/${fn}.env.sh'"
done
Expand All @@ -111,14 +119,14 @@ libsh__load() {
libsh__exit_with_message "ERR" "Something went wrong in loading libsh."
fi

if [ ${LIBSH_CHECK_BY_DATE} ]; then
if [ "${LIBSH_CHECK_BY_DATE}" ]; then
libsh__check_by_date
fi
}

# if we get an arg, load the things!
[ -z "${1}" ] && libsh__exit_with_message "ERR" "I need to know if you want to load 'fn' or 'env'. Instead I got: '${1}'."
[[ "$1" = "fn" || "$1" = "env" ]] && libsh__load ${1} || libsh__exit_with_message "ERR" "I did not get fn or env. Instead I got: '$1'"
( [[ "$1" = "fn" || "$1" = "env" ]] && libsh__load "${1}" ) || libsh__exit_with_message "ERR" "I did not get fn or env. Instead I got: '$1'"


#
Expand Down
2 changes: 2 additions & 0 deletions libsh_utils.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

# exit with problem and not exit shell
libsh__exit_with_message() {
echo "$1: $2"
Expand Down
2 changes: 2 additions & 0 deletions lpass.env.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#!/usr/bin/env bash

[ ! -z ${ENABLE_LPASS_AGENT_TIMEOUT} ] && \
export set LPASS_AGENT_TIMEOUT="${ENABLE_LPASS_AGENT_TIMEOUT-300}"
2 changes: 2 additions & 0 deletions npm.env.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

# npm env

# npm command found?
Expand Down
4 changes: 3 additions & 1 deletion npm.sh
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# npm
#!/usr/bin/env bash

# npm
3 changes: 3 additions & 0 deletions nvm.env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export NVM_DIR="$HOME/.nvm"
[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh" # This loads nvm
[ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion
6 changes: 6 additions & 0 deletions nvm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# nvm
nvm_install() {
command -v nvm > /dev/null
[ "${?}" = "0" ] || brew install nvm
[[ -d $HOME/.nvm ]] || mkdir $HOME/.nvm
}
2 changes: 2 additions & 0 deletions ohmyzsh.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

ohmyzsh_validate() {
[ -z $ZSH_CUSTOM ] && export ZSH_CUSTOM=$HOME/.oh-my-zsh/custom
}
Expand Down
2 changes: 2 additions & 0 deletions options.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

case $SHELL in
*zsh)
command -v setopt > /dev/null
Expand Down
2 changes: 2 additions & 0 deletions paths.env.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

[ -d $HOME/.local/bin ] && libsh__add_path "pre" "$HOME/.local/bin"
[ -d /usr/local/bin ] && libsh__add_path "pre" "/usr/local/bin"
[ ! -z $LIBSH_CDPATH ] && export CDPATH=$LIBSH_CDPATH
2 changes: 2 additions & 0 deletions pyenv.env.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

if [ -d $HOME/.pyenv ]; then
# set the PYENV_ROOT
export PYENV_ROOT="$HOME/.pyenv"
Expand Down
2 changes: 2 additions & 0 deletions pyenv.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

if [ -d $HOME/.pyenv ]; then
eval "$(pyenv init --path)"
# execute the eval
Expand Down
2 changes: 2 additions & 0 deletions python.env.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

## disabled until I find a reason to use "workon" because its confusing
# set your python workon home or use default
# [ -n "$LIBSH_PYTHON_WORKON_HOME" ] && \
Expand Down
Loading