Skip to content

Commit

Permalink
Merge pull request #105 from benknoble/dev-1.4
Browse files Browse the repository at this point in the history
1.4 Features
  • Loading branch information
benknoble committed Oct 15, 2017
2 parents 22f7751 + 73e8697 commit cf6e536
Show file tree
Hide file tree
Showing 19 changed files with 194 additions and 60 deletions.
2 changes: 1 addition & 1 deletion Brewfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ brew "gdbm"
brew "perl"
brew "git"
brew "gnu-sed"
brew "htop"
brew "hub"
brew "openssl"
brew "libgpg-error"
Expand All @@ -31,7 +32,6 @@ brew "moreutils"
brew "nethack"
brew "pkg-config"
brew "sqlite"
brew "python3"
brew "ponysay"
brew "proselint"
brew "pstree"
Expand Down
1 change: 1 addition & 0 deletions bash/aliases.bash
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ alias beep="echo -n $'\a'" # Do a beep
alias today='date -j +"%e %B %Y"' # A format of the date
alias battery='pmset -g batt' # Display battery info
alias lvim='vim -c ''"normal '"'0"'"' # Start vim with it's last cursor position
alias screensaver='open -a ScreenSaverEngine' # Start the screensaver
62 changes: 45 additions & 17 deletions bash/functions.bash
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,25 @@ displayPath () { echo "${PATH//:/$'\n'}" ; } # Print path separated by newlines
mkcd () { mkdir "$@" && cd "$@" ; } # mkdir and cd
editall () { vim -p "$@" ; } # edit all files provided as arguments in vim tabs
extract () { # attempt to extract file with correct extraction method
if [ -f "$1" ]; then
case "$1" in
*.tar.bz2) tar xjf "$1" ;;
*.tar.gz) tar xzf "$1" ;;
*.bz2) bunzip2 "$1" ;;
*.rar) unrar x "$1" ;;
*.gz) gunzip "$1" ;;
*.tar) tar xf "$1" ;;
*.tbz2) tar xjf "$1" ;;
*.tgz) tar xzf "$1" ;;
*.zip) unzip "$1" ;;
*.Z) uncompress "$1" ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
for file in "$@"; do
if [ -f "$file" ]; then
case "$file" in
*.tar.bz2) tar xjf "$file" ;;
*.tar.gz) tar xzf "$file" ;;
*.bz2) bunzip2 "$file" ;;
*.rar) unrar x "$file" ;;
*.gz) gunzip "$file" ;;
*.tar) tar xf "$file" ;;
*.tbz2) tar xjf "$file" ;;
*.tgz) tar xzf "$file" ;;
*.zip) unzip "$file" ;;
*.Z) uncompress "$file" ;;
*) echo "'$file' cannot be extracted via extract()" ;;
esac
else
echo "'$file' is not a valid file"
fi
done
}

pathadd() { # add to path
Expand All @@ -44,5 +46,31 @@ freewrite() {

getip() {
ipconfig getifaddr en0
}

quote() {
printf %s\\n "$1" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/'/"
}

# joinby delim args
join_by() {
local d=$1
shift
echo -n "$1"
shift
printf "%s" "${@/#/$d}"
echo
}

# mktouch path/to/file ...
mktouch() {
if [ $# -lt 1 ]; then
echo "Missing argument" >&2
return 1
fi

for f in "$@"; do
mkdir -p -- "$(dirname -- "$f")"
touch -- "$f"
done
}
71 changes: 53 additions & 18 deletions bashrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export EDITOR=vim
# use my color scheme for ls
export LSCOLORS="gxfxcxdxbxegedabagacad"

# use less on any system
export PAGER="less"

# Message of the Day control
# COW controls which cow to use (use `cowsay -l` or `cowvis` for options)
# COLOR controls whether or not to use lolcat for color (0=yes, 1+=no)
Expand All @@ -27,6 +30,28 @@ PS2="» "
# set PS3
PS3="$PS2"

# file to hold private keys
private=~/.private
# completion paths
brewcomp=/usr/local/etc/bash_completion.d/brew
caskcomp=/usr/local/etc/bash_completion.d/brew-cask
scalacomp=/usr/local/Cellar/scala/2.12.3/etc/bash_completion.d/scala
bashcomp=/usr/local/share/bash-completion/bash_completion

# use nullglob (if glob doesn't expand into anything, it is not preserved as literal text)
shopt -s nullglob

# don't accidentally overwrite files with '>' (use '>|' to force overwriting)
set -o noclobber

# let 'space' magically expand history command-line fu
# use M-C-e to expand *all* command-line fu
bind Space:magic-space

HISTSIZE=100000
HISTFILESIZE="$HISTSIZE"
shopt -s histappend

# reload profile
alias reload='. ~/.bashrc >/dev/null && echo "reloaded"'

Expand All @@ -49,22 +74,21 @@ source ~/Dotfiles/bash/gitconfig.bash
source ~/Dotfiles/bash/PS1.bash

# source .private for meant to never be seen
private=~/.private
[[ -r "$private" ]] && source "$private"

# use nullglob (if glob doesn't expand into anything, it is not preserved as literal text)
shopt -s nullglob

# don't accidentally overwrite files with '>' (use '>|' to force overwriting)
set -o noclobber

# let 'space' magically expand history command-line fu
# use M-C-e to expand *all* command-line fu
bind Space:magic-space

HISTSIZE=100000
HISTFILESIZE="$HISTSIZE"
shopt -s histappend
# source anything in ~/.personal
if [[ -d ~/.personal ]]; then
for file in ~/.personal/*.sh; do
if [[ -r ~/.personal ]]; then
source "$file"
fi
done
unset file
# add ~/.personal/bin to path
if [[ -d ~/.personal/bin ]]; then
pathadd "$HOME/.personal/bin"
fi
fi

# Add bin folder for scripts to path
pathadd "$HOME/Dotfiles/bin"
Expand All @@ -80,23 +104,34 @@ complete -o default -F _pip_completion pip
# pip bash completion end

# brew completion if possible
brewcomp=/usr/local/etc/bash_completion.d/brew
[[ -s "$brewcomp" ]] && source "$brewcomp"
# and brew cask
caskcomp=/usr/local/etc/bash_completion.d/brew-cask
[[ -s "$caskcomp" ]] && source "$caskcomp"

# scala completion if possible
scalacomp=/usr/local/Cellar/scala/2.12.3/etc/bash_completion.d/scala
[[ -s "$scalacomp" ]] && source "$scalacomp"

# bash completion
bashcomp=/usr/local/share/bash-completion/bash_completion
[[ -s "$bashcomp" ]] && source "$bashcomp"

# add brew ext commands to path
pathadd "$brewscripts/ext"

# Handle commands not found
if [[ "$(type -t command_not_found_handle)" != function ]]; then
command_not_found_handle() {
{
echo -e "$BRed"Command not found: "$NC$BYellow$1$NC"
shift
if [[ $# -gt 0 ]]; then
echo "$#" args: "$(join_by ', ' "${@@Q}")"
fi
echo -e Try "$BGreen"'`displayPath`'"$NC" to see the path
} >&2
return 127
}
fi

# Message of the Day
# COW controls which cow to use (use `cowsay -l` or `cowvis` for options)
# COLOR controls whether or not to use lolcat for color (0=yes, 1+=no)
Expand Down
24 changes: 24 additions & 0 deletions bin/figvis
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#! /bin/bash
# a figlet font visualizing program

USAGE="$(cat <<EOF
usage: $0
Visualize all the fonts. Press 'q' to quit.
Supply options to get this message.
EOF
)"

if [[ $# -gt 0 ]]; then
echo "$USAGE" >&2
exit 2
fi

cols=$(tput cols)
read -a fonts <<<$(figlist | awk '/Figlet/{p=!p;next}p')

for font in "${fonts[@]}"; do
figlet -w "$cols" -f "$font" "$font"
echo "$font"
done | less
2 changes: 1 addition & 1 deletion bootstrap.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /bin/bash -
#! /usr/bin/env bash
# bootstrap is not quite the correct term for this installer based on wikipedia,
# but it is more fun than 'setup.' The script will execute commands from the
# setup directory to get things running
Expand Down
2 changes: 1 addition & 1 deletion brew/brewutils.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /bin/bash -
#! /usr/bin/env bash
# contains utility functions for brew scripts

function brew_exists() {
Expand Down
4 changes: 4 additions & 0 deletions docs/aliases.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,7 @@ accessed with `<F1>`.
**`lvim`**

*Open your last vim position.* Because you needed *another* way to invoke vim.

**`screensaver`**

*SOS: Save our screen!*
14 changes: 14 additions & 0 deletions docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ completion if it can find it.
It will be sourced, but it doesn't get included in version control. Keep it
private.

- **~/.personal/** is a directory where you can keep personal tweaks. Every
`*.sh` file will get *sourced* (**not executed**) at startup. This is a great
place to tweak env variables unique to your machine, like COW, a completion
path, or a PATH. This is different from the **.private** above--this is meant to
be potentially version-controlled, so you get my setup, your tweaks, and no
conflicts. Particularly relevant if you work on multiple types of machines, and
some things need tweaks (`ls` flags, e.g.).

- **~/.personal/bin** is a directory of executables that gets added to your PATH
if it exists.

### Inputrc

*Tune input in bash.* This gives me opt+{left,right} in bash to move between
Expand All @@ -87,6 +98,9 @@ you with their names so you can pick your favorites.
- **exit_msg** is a script I put together for exiting other scripts with a useful
message. Read it's docs.

- **figvis** is like cowvis: get a visual representation of fonts from
`figlet`

- **isnumber** takes input and decides whether it is a valid number or not.

- **itunes** gives you CLI control of iTunes. The disadvantage? If iTunes isn't
Expand Down
21 changes: 20 additions & 1 deletion docs/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Variadic: `file[s...]` to open.
*Inflate an archive.* Guesses based on the file extension the correct extraction
method and applies it, failing with a message if not possible.

1 argument: `archive` to extract.
Variadic: `archive[s...]` to extract.

**`pathadd`**

Expand All @@ -80,3 +80,22 @@ in. 'Cause you're free, free writin'.
*Display IP Address.* Does not get you tips.

0 arguments.

**`quote`**

*Quote a string.* Useful if you're having quote problems in bash.

1 argument: `string` to quote.

**`join_by`**

*Join values with a delimiter*. Used by completion not found handle, found
in [bashrc](/bashrc).

Variadic: `delim` `string[s...]` to join

**`mktouch`**

*Touch a file whose path doesn't exist.*

1 argument: `/path/to/file`
9 changes: 5 additions & 4 deletions docs/tree.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
│   ├── checkdistnoted
│   ├── cowvis
│   ├── exit_msg
│   ├── figvis
│   ├── isnumber
│   ├── itunes
│   ├── listcmds
Expand Down Expand Up @@ -47,13 +48,13 @@
│   ├── 01-tree
│   └── 02-brew
├── inputrc
├── installers
│   ├── install-brew.sh
│   ├── install-git-extras.sh
│   └── install-vim-custom.sh
├── setup
│   ├── git-setup.sh
│   ├── install-all.sh
│   ├── installers
│   │   ├── install-brew.sh
│   │   ├── install-git-extras.sh
│   │   └── install-vim-custom.sh
│   └── makesymlinks.sh
├── update.sh
├── vim
Expand Down
2 changes: 1 addition & 1 deletion setup/git-setup.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /bin/bash -
#! /usr/bin/env bash
# git setup

# config function
Expand Down
5 changes: 3 additions & 2 deletions setup/install-all.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#! /bin/bash -
#! /usr/bin/env bash
# an install script to install custom stuff
# executes all scripts in ./installers/, which makes it prone to attack if not careful.
# however, it also allows you to add your own installer scripts

find ~/Dotfiles/installers/ -maxdepth 1 -type f -name "*.sh" -ok sh {} \;
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
find "$DIR"/installers -maxdepth 1 -type f -name "*.sh" -ok sh {} \;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /bin/bash -
#! /usr/bin/env bash
# installer script for brew and certain formulae

_install_brew() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /bin/bash -
#! /usr/bin/env bash
# installer script for git extras

echo
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /bin/bash -
#! /usr/bin/env bash
# installer script for Pathogen and certain vim plugins

echo
Expand Down

0 comments on commit cf6e536

Please sign in to comment.