Permalink
Browse files

created a `foobar.fish` for messing around with different functionali…

…ty of fish shell functions, created `/opt/Code/dotfiles/config/zsh` for storing Zsh configuration files, and setup BASH to source `function` files stored within `/Users/capin/.config/bash/functions`
  • Loading branch information...
ipatch committed Jun 5, 2018
1 parent 121279e commit d83a9565ea0ef710365675b2314cb7745e990abe
2 .wiki
Submodule .wiki updated from 445ce3 to 1bf1ab
No changes.
@@ -0,0 +1,63 @@
##############################
# User specified file for configuring BASH.
# Author: Chris Jones
# Contact: @truckmonth <- twitter
# Contact: chris.r.jones.1983@gmail.com <- email
# Contact: @ipatch <- github
##

# test if `~/.profile` exsits, then load it
if [ -f "$HOME/.profile" ]; then
source "$HOME/.profile"
fi

# test for `rvm` with `~/.rvm/scripts/rvm` then load
if [ -f "$HOME/.rvm/scripts/rvm" ]; then
source "$HOME/.rvm/scripts/rvm"
fi

# set the size of the command history in bytes
HISTSIZE=1000000 # 1 Megabyte a.k.a 1MB

# test for git completions and git prompt
OS=$(uname)
if [[ $OS == Darwin ]]; then
if [ -f "/Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-completion.bash" ]; then
source "/Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-completion.bash"
fi
if [ -f "/Applications/Xcode.app/Contents/Develper/usr/share/git-core/git-prompt.sh" ]; then
source "/Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-prompt.sh"
fi

# TODO: figure out why below 2 env vars were not loading properly
#GIT_PS1_SHOWDIRTYSTATE=true;

#PS1='\[\033[32m\]\u@\h\[\033[00m\]:\[\033[34m\]\w\[\033[31m\]$(__git_ps1)\[\033[00m\]\$ ';

fi


# 💳 https://stackoverflow.com/a/18915067/708807

SSH_ENV="$HOME/.ssh/environment"

function start_agent {
echo "Initialising new SSH agent..."
/usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
echo succeeded
chmod 600 "${SSH_ENV}"
. "${SSH_ENV}" > /dev/null
/usr/bin/ssh-add;
}

# Source SSH settings, if applicable

if [ -f "${SSH_ENV}" ]; then
. "${SSH_ENV}" > /dev/null
#ps ${SSH_AGENT_PID} doesn't work under cywgin
ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
start_agent;
}
else
start_agent;
fi
@@ -0,0 +1,101 @@
#!/usr/bin/env bash
##############################
# User specified file for configuring BASH.
# Author: Chris Jones
# Contact: @truckmonth <- twitter
# Contact: chris.r.jones.1983@gmail.com <- email
# Contact: @ipatch <- github
##

# shellcheck source=/dev/null

##############################
# NOTE: in macOS ~/.bashrc is loaded before ~/.bash_profile
# 1) /etc/profile
# 2) /etc/bash.bashrc
# 3) ~/.bashrc # NOTE: this file is used for interactive shell sessions
# 4) ~/.bash_profile # NOTE: this file is used for login shells
# NOTE: for a deeper understanding of `interactive/login` see "INVOCATION" in the BASH man page.
# 5) ~/.bash_login
# 6) ~/.profile
# 7) ~/.bash_logout
##

## Extremely helpful for debugging BASH scripts
#set -x
#trap read debug

# Env Vars

# User details
export USERNAME="capin"
export NICKNAME="capin"

export XDG_CONFIG_HOME="$HOME/.config"
export code="/opt/code"
export dots="/opt/code/dotfiles"
export github="/opt/code/github"

# Env Vars for git
export GIT_RC="$XDG_CONFIG_HOME/git"

##############################
# Aliases for interactive shell sessions
##
alias ..='cd ..'
alias cd..='cd ..'
alias l='ls -lahF'
alias cp='cp -iv'
alias rm='rm -iv'
alias mv='mv -iv'

# `git` aliases for git projects
alias gs='git status'
alias gd='git diff --stat'
alias ga='git add --all'
alias gp='git push'

# "storage" aliases
alias df='df -h'
alias du='du -h'

alias dotfiles='cd /opt/Code/dotfiles'


# NOTE: functions in BASH are all stored in memory, ie. RAM and not on disk
# test to see if a functions dir exists with `$XDG_CONFG_HOME`
if [ -d ~/.config/bash/functions ]; then
export funcs_dir="$HOME/.config/bash/functions"
for file in "$funcs_dir"/*.bash;
do
source "$file";
done
fi

# check to see if $HOME/.bash_profile exists then load in current shell session.
if [ -f ~/.bash_profile ]; then
source ~/.bash_profile
fi

# TODO: create a `paths` func to load paths into `PATH`
export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting
export PATH="$PATH:/home/linuxbrew/.linuxbrew/bin/" # Add linuxbrew to the PATH

# source helpful files for working with the `asdf` version manager
if [ -f ~/.asdf/asdf.sh ]; then
source ~/.asdf/asdf.sh
fi

if [ -f ~/.asdf/completions/asdf.bash ]; then
source ~/.asdf/completions/asdf.bash
fi

# source helpful file for working with `fzf` CLI fuzzy finder
# NOTE: the below statement tests to see the `.fzf.bash` file exists in ~ and then loads into the interactive BASH session.
if [ -f ~/.fzf.bash ]; then
source ~/.fzf.bash
fi

# [ -f ~/.fzf.bash ] && source ~/.fzf.bash


No changes.
@@ -0,0 +1,17 @@
> BASH functions stored in this direcotry do not require an executable bit in order to run.
To test uncomment

```bash
echo "Hello, BASH!"
```

from the `foobar.bash` file.

If everything works as intended functions defined within the `$XDG_CONFIG_HOME/functions` or the `$funcs_dir` should load the function files, ie. `foobar.bash` and the functions loaded within them.

To test the above behavior, run the `hello` function from the CLI that is contained within the `foobar.bash` file in the `$funcs_dir` by running,

```bash
hello
```
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

# Usuage: DEBUG=true ./mr-buggy-bash-script.sh

function debug {
if [ "$DEBUG" = "true" ] ; then
if [ "$1" = "on" ] || [ "$1" = "ON" ] ; then
set -x
else
set +x
fi
fi
}
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

# echo "Hello, BASH!"

function hello() {
echo "My name is Chris"
}
@@ -0,0 +1,34 @@
function color --description 'select a base16-shell colorscheme'

# echo "boo"

set BASE16_DIR ~/.config/base16-shell
set BASE16_CONFIG ~/.vim/.base16

function _fish_color
set BACKGROUND "$1"
SCHEME "$2"

if [ (count $argv) -eq -a -s "$BASE16_CONFIG" ]
cat ~/.vim/.base16
return
end

if [[ "$SCHEME" = 'help' ]]
set BACKGROUND 'help'
end

switch "$BACKGROUND"
case dark or light
set FILE "$BASE16_DIR/base16-$SCHEME.$BACKGROUND.sh"
if [[ -x "$FILE" ]]
echo "$SCHEME" > "$BASE16_CONFIG"
echo "$BACKGROUND" >> "$BASE16_CONFIG"
"$FILE"
else
# FINISH
end

end
end
end
@@ -1,15 +1,17 @@
function colors --description 'select a base16-shell colorscheme'
function color --description 'select a base16-shell colorscheme'

# echo "boo"
# Usage: [`light|dark` <name_of_colorscheme>]
# Example: `dark tomorrow`
# Help: `color help`

set BASE16_DIR ~/.config/base16-shell
set BASE16_CONFIG ~/.vim/.base16

function _fish_color
function __fish_color
set BACKGROUND "$1"
SCHEME "$2"

if [ (count $argv) -eq -a -s "$BASE16_CONFIG" ]
if [ (count $argv) -eq 0 -a -s "$BASE16_CONFIG" ]
cat ~/.vim/.base16
return
end
@@ -22,13 +24,53 @@ function _fish_color
case dark or light
set FILE "$BASE16_DIR/base16-$SCHEME.$BACKGROUND.sh"
if [[ -x "$FILE" ]]
echo "$SCHEME" > "$BASE16_CONFIG"
echo "$BACKGROUND" >> "$BASE16_CONFIG"
"$FILE"
else
# FINISH
echo "$SCHEME" > "$BASE16_CONFIG"
echo "$BACKGROUND" >> "$BASE16_CONFIG"
"$FILE"
else
# FINISH
echo "Scheme '$SCHEME' not found in $BASE16_DIR
return 1
end
case help
echo 'color dark [ocean|grayscale|ashes|default|railscasts|tomorrow|twilight|...]'
echo 'color light [grayscale|harmonic16|ocean|tomorrow|twilight|...]'
echo
echo 'Available schemes:'
find ~/.config/base16-shell -name 'base16-*.sh' | \
sed -E 's|.*/base16-||' | \
sed -E 's/\.(dark|list)\.sh/ (\1)/' | \
column
case '*'
echo 'Unknown subcommand: use one of {dark,light,help}'
end
end # function __fish_color
function __fish_dark
__fish_color dark "$argv[1]"
end
function __fish_light
__fish_light light "$argv[1]"
end
if [[ -s "$BASE16_CONFIG" ]];
set SCHEME (head -1 "$BASE16_CONFIG")
set BACKGROUND (sed -n -e '2 p' "$BASE16_CONFIG")
if [ "$BACKGROUND" = 'dark' ]
dark "$SCHEME"
else if
light "$SCHEME"
else
echo "error: unknown background type in $BASE16_CONFIG"
end
else
# default
dark ocean
end
end
end
end
@@ -0,0 +1,17 @@
function foobar --description "a nolvety function to aid my understanding of fish"

echo "function `foobar` was executed"

set FOO mr-fancy-bar

echo "The output of FOO = $FOO"

# NOTE: the below statement will echo the literally not executing the `set` builtin command for fish
echo "(set -S FOO)"
# OUTPUT: `(set -S FOO)`

# NOTE: the below statement will echo the output of the `set` builtin fish command
echo (set -S FOO)
# OUTPUT: `$FOO: set in local scope, ...`

end
@@ -0,0 +1,14 @@
# Setup fzf
# ---------
if [[ ! "$PATH" == */usr/local/opt/fzf/bin* ]]; then
export PATH="$PATH:/usr/local/opt/fzf/bin"
fi

# Auto-completion
# ---------------
[[ $- == *i* ]] && source "/usr/local/opt/fzf/shell/completion.zsh" 2> /dev/null

# Key bindings
# ------------
source "/usr/local/opt/fzf/shell/key-bindings.zsh"

File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.

0 comments on commit d83a956

Please sign in to comment.