refactor: reduce sourcing (#4)
* refactor: reduce sourcing * docs: readme update * docs: comments on managed blocks
This commit is contained in:
parent
e495948098
commit
a5b44abdce
6 changed files with 83 additions and 79 deletions
27
README.md
27
README.md
|
@ -1,17 +1,20 @@
|
|||
# Shell goodies
|
||||
# 🥫Environment-in-a-can
|
||||
|
||||
A collection of shell enhancement for everyday happiness.
|
||||
Environment tweaks for everyday happiness.
|
||||
|
||||
## Setup
|
||||
|
||||
```bash
|
||||
git clone git@github.com:mcataford/env.git ~/.env_goodies | . ./setup
|
||||
git clone git@github.com:mcataford/env.git <path-of-your-choosing> | . ./setup
|
||||
```
|
||||
|
||||
## Updating existing setups
|
||||
The setup script will look for pre-existing managed blocks and will not update the file if one is found.
|
||||
|
||||
Since `~/.env_goodies` is a cloned repository, pulling new changes should update everything. You may need to `source`
|
||||
the shell configuration file again for new goodies to apply.
|
||||
### Updating existing setups
|
||||
|
||||
Since the managed blocks only `source` the files in this repository, pulling in updates from remote should bring in any
|
||||
new tweaks you want to apply. If changes are made to the managed blocks, you will need to first remove them from where
|
||||
they live and rerun the setup script.
|
||||
|
||||
## Structure
|
||||
|
||||
|
@ -20,10 +23,12 @@ The package is structured as such:
|
|||
```
|
||||
env/
|
||||
setup # Adds bootstrap block to your shell's config file.
|
||||
source/
|
||||
... # Anything here is sourced on shell-start
|
||||
extras.vim # Common config for NVIM
|
||||
shell_extras # Functions, aliases and exports for the shell.
|
||||
extras.vim # Common config for NVIM.
|
||||
```
|
||||
|
||||
Adding files to `source/` will add code that gets executed on shell-start. Files are discovered by globbing in the
|
||||
bootstrap block added by `setup` and do not need to be registered anywhere.
|
||||
Adding code to `shell_extras` will add code that gets executed on shell-start.
|
||||
|
||||
## Contributing
|
||||
|
||||
I'm not currently looking for contributions since this is mainly about standardizing my own setup across machines.
|
||||
|
|
11
setup
11
setup
|
@ -8,19 +8,22 @@ set -e
|
|||
#
|
||||
|
||||
BLOCK_DELIMITER_PATTERN="mcataford/env-managed-block"
|
||||
WORKING_PATH=$(realpath $(dirname $0))
|
||||
WORKING_PATH=$(git rev-parse --show-toplevel)
|
||||
SHELL_CONFIG_PATH=""
|
||||
|
||||
# First, we need to know if we're dealing with ZSH or Bash.
|
||||
if [[ -n $(echo $SHELL | grep zsh) ]]; then
|
||||
SHELL_CONFIG_PATH="$HOME/.zshrc"
|
||||
else
|
||||
SHELL_CONFIG_PATH="$HOME/.bashrc"
|
||||
fi
|
||||
|
||||
# A managed block is added to source the `shell_extras` file
|
||||
# in the shell configuration (either `.zshrc` or `.bashrc`).
|
||||
echo "Setting up shell configuration extras..."
|
||||
if [[ -z $(cat $SHELL_CONFIG_PATH | grep $BLOCK_DELIMITER_PATTERN) ]]; then
|
||||
echo "# $BLOCK_DELIMITER_PATTERN\:start
|
||||
for source_files in ~/.env_goodies/source/*; do source $source_files; done
|
||||
source $WORKING_PATH/shell_extras
|
||||
# $BLOCK_DELIMITER_PATTERN\:end" >> $SHELL_CONFIG_PATH
|
||||
echo "✅ Added managed block to $SHELL_CONFIG_PATH"
|
||||
else
|
||||
|
@ -30,11 +33,13 @@ fi
|
|||
EDITOR_CONFIG=$HOME/.config/nvim
|
||||
EDITOR_CONFIG_FILE=$EDITOR_CONFIG/init.vim
|
||||
|
||||
# Similarly, sourcing for `extras.vim` is added to the vim configuration
|
||||
# so plugins, bindings and whatnot are loaded on start.
|
||||
if [[ -f $EDITOR_CONFIG_FILE ]]; then
|
||||
echo "Setting up NVIM configuration extras..."
|
||||
if [[ -z $(cat $EDITOR_CONFIG_FILE | grep $BLOCK_DELIMITER_PATTERN) ]]; then
|
||||
echo "\" $BLOCK_DELIMITER_PATTERN\:start
|
||||
source $HOME/.env_goodies/extras.vim
|
||||
source $WORKING_PATH/extras.vim
|
||||
\" $BLOCK_DELIMITER_PATTERN\:end\n\n" >> $EDITOR_CONFIG_FILE.new
|
||||
cat $EDITOR_CONFIG_FILE >> $EDITOR_CONFIG_FILE.new
|
||||
|
||||
|
|
59
shell_extras
Normal file
59
shell_extras
Normal file
|
@ -0,0 +1,59 @@
|
|||
#!/usr/bin/bash
|
||||
|
||||
################
|
||||
# ALIASES #
|
||||
################
|
||||
|
||||
# TMUX things.
|
||||
|
||||
# Lists all sessions
|
||||
alias ts="tmux ls"
|
||||
|
||||
# Attaches to session with name $1
|
||||
alias ta="tmux attach -t $1"
|
||||
|
||||
# Create new session with provided name.
|
||||
alias tm="tmux new -s $1"
|
||||
|
||||
# VIM/NVIM things.
|
||||
|
||||
# All roads lead to nvim.
|
||||
alias vim=nvim
|
||||
alias v=nvim
|
||||
|
||||
##############
|
||||
# FUNCTIONS #
|
||||
##############
|
||||
|
||||
# Autoupdates the env setup.
|
||||
function env_autoupdate {
|
||||
SHELL_CONFIG_PATH=""
|
||||
|
||||
if [[ -n $(echo $SHELL | grep zsh) ]]; then
|
||||
SHELL_CONFIG_PATH="$HOME/.zshrc"
|
||||
else
|
||||
SHELL_CONFIG_PATH="$HOME/.bashrc"
|
||||
fi
|
||||
|
||||
|
||||
{
|
||||
cd ~/.env_goodies
|
||||
git pull
|
||||
source $SHELL_CONFIG_PATH
|
||||
cd -
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
# Inspects available aliases based on a grep query.
|
||||
function which_alias {
|
||||
alias | grep $1
|
||||
}
|
||||
|
||||
#############
|
||||
# EXPORTS #
|
||||
#############
|
||||
|
||||
# Ensures that passphrases can be entered when signing
|
||||
# git commits.
|
||||
export GPG_TTY=$(tty)
|
|
@ -1,42 +0,0 @@
|
|||
################
|
||||
# TMUX-related #
|
||||
################
|
||||
|
||||
# Lists all sessions
|
||||
alias ts="tmux ls"
|
||||
|
||||
# Attaches to session with name $1
|
||||
alias ta="tmux attach -t $1"
|
||||
|
||||
# Create new session with provided name.
|
||||
alias tm="tmux new -s $1"
|
||||
|
||||
###############
|
||||
# VIM-related #
|
||||
###############
|
||||
|
||||
# All roads lead to nvim.
|
||||
alias vim=nvim
|
||||
alias v=nvim
|
||||
|
||||
###############
|
||||
# git-related #
|
||||
###############
|
||||
|
||||
unalias mgs 2>/dev/null
|
||||
alias mgs="git status"
|
||||
|
||||
unalias mgf 2>/dev/null
|
||||
alias mgf="git fetch"
|
||||
|
||||
unalias mgc 2>/dev/null
|
||||
alias mgc="git commit"
|
||||
|
||||
unalias mgp 2>/dev/null
|
||||
alias mgp="git push"
|
||||
|
||||
unalias mgcb 2>/dev/null
|
||||
alias mgcb="git branch --show-current"
|
||||
|
||||
unalias mgl 2>/dev/null
|
||||
alias mgl="git log"
|
|
@ -1,18 +0,0 @@
|
|||
function env_autoupdate {
|
||||
SHELL_CONFIG_PATH=""
|
||||
|
||||
if [[ -n $(echo $SHELL | grep zsh) ]]; then
|
||||
SHELL_CONFIG_PATH="$HOME/.zshrc"
|
||||
else
|
||||
SHELL_CONFIG_PATH="$HOME/.bashrc"
|
||||
fi
|
||||
|
||||
|
||||
{
|
||||
cd ~/.env_goodies
|
||||
git pull
|
||||
source $SHELL_CONFIG_PATH
|
||||
cd -
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Ensures that passphrases can be entered when signing
|
||||
# git commits.
|
||||
export GPG_TTY=$(tty)
|
Loading…
Reference in a new issue