Initial commit with core behavior

This commit is contained in:
Luke 2019-10-06 15:47:07 -07:00
commit 8c66602158
12 changed files with 502 additions and 0 deletions

13
0-loader Normal file
View file

@ -0,0 +1,13 @@
#!/bin/bash
# These lines are to be appended to the default Ubuntu bashrc script
# the only line I add to modify this file Add this file to the end of your
# .bashrc to get whatever the defaults are there, then this scrilt will
# scrape your .bashrc.d directory for *.sh files and load them into your
# enviornment.
if [[ -e ${HOME}/.bashrc.d ]]; then
for __import_file in "${HOME}/.bashrc.d/"*".sh"; do
source $__import_file
done
unset __import_file
fi

24
LICENSE Normal file
View file

@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org>

48
aliases.sh Normal file
View file

@ -0,0 +1,48 @@
#!/bin/bash
################################################################################
# The first step is to try to remove the default aliases that I don't want
# to deal with. These are currently (as of Ubuntu 17.10) l, la, ll
function alias_exists() {
SEARCH_KEY="$1"
alias | cut -d= -f1 | cut -d\ -f2 | grep "^${SEARCH_KEY}\$" &>/dev/null
return $?
}
# list of aliases to remove
__removeAliases=(ll l la)
for __testAlias in ${__removeAliases[@]}; do
if alias_exists "$__testAlias"; then
unalias $__testAlias
fi
done
# cleanup after ourselves
unset __removeAliases
unset __testAlias
################################################################################
alias fdiff="sdiff -t --tabsize=4 -w \$(tput cols) -b"
alias rsync-prog="rsync -Pav"
alias parallel="parallel --no-notice"
if [[ -e /opt/eagle/eagle/eagle ]]; then
alias eagle=$(readlink -f /opt/eagle/eagle/eagle)
fi
# Stopwatch
alias timer='echo "Timer started. Stop with Ctrl-D." && date && time cat && date'
# IP addresses
alias pubip="dig +short myip.opendns.com @resolver1.opendns.com"
if [[ ! "$(which dropbox)" && "$(which caja-dropbox)" ]]; then
alias dropbox=caja-dropbox
fi
if [[ "$(which ncdu)" ]]; then
alias dush="ncdu --color dark -rr"
else
alias dush="echo please 'apt install ncdu'"
fi

43
ffmpegBatch.sh Normal file
View file

@ -0,0 +1,43 @@
#!/bin/bash
function batchConvertFLAC() {
IFS=$'\n'
INPUT_EXT="${1:-.flac}"
INPUT_DIR="${2:-./}"
OUT_DIR="${3:-./output}"
if [[ "${INPUT_DIR: -1}" != "/" ]]; then
INPUT_DIR="$INPUT_DIR/"
fi
if [[ "${OUT_DIR: -1}" != "/" ]]; then
OUT_DIR="$OUT_DIR/"
fi
if [[ ! -e "$OUT_DIR" ]]; then
mkdir -pv "$OUT_DIR"
fi
jMax=${JOBS:-4};
pids=()
FROM="$(readlink -f "$INPUT_DIR")/"
TO="$(readlink -f "$OUT_DIR")/"
(
cd "$FROM"
for FLAC in *$INPUT_EXT; do
echo "Converting '$INPUT_DIR$FLAC'..."
while [[ "$(jobs -r | wc -l)" -ge $jMax ]]; do
sleep 0.1
done
IN_FILE="$FLAC"
OUT_FILE="$TO${FLAC/.flac/.m4a}"
#echo "$OUT_FILE"
ffmpeg -i "$IN_FILE" -n -ab 192k -vn "$OUT_FILE" &>/dev/null &
pids[${i}]=$!
done
for PID in ${pids[@]}; do
wait $PID
done
echo "done."
)
}
#complete -F _minimal batchConvert

109
functions.sh Normal file
View file

@ -0,0 +1,109 @@
#!/bin/bash
sumList() { SIZE=$(ls -FaGl "${@}" | awk '{ total += $4 }; END { print total }'); echo $(($SIZE/1024)); }
# Simple calculator
calc() {
local result=""
result="$(printf "scale=10;%s\\n" "$*" | bc --mathlib | tr -d '\\\n')"
# └─ default (when `--mathlib` is used) is 20
if [[ "$result" == *.* ]]; then
# improve the output for decimal numbers
# add "0" for cases like ".5"
# add "0" for cases like "-.5"
# remove trailing zeros
printf "%s" "$result" |
sed -e 's/^\./0./' \
-e 's/^-\./-0./' \
-e 's/0*$//;s/\.$//'
else
printf "%s" "$result"
fi
printf "\\n"
}
# Create a data URL from a file
dataurl() {
local mimeType
mimeType=$(file -b --mime-type "$1")
if [[ $mimeType == text/* ]]; then
mimeType="${mimeType};charset=utf-8"
fi
echo "data:${mimeType};base64,$(openssl base64 -in "$1" | tr -d '\n')"
}
# Run `dig` and display the most useful info
digga() {
dig +nocmd "$1" any +multiline +noall +answer
}
# UTF-8-encode a string of Unicode symbols
escape() {
local args
mapfile -t args < <(printf "%s" "$*" | xxd -p -c1 -u)
printf "\\\\x%s" "${args[@]}"
# print a newline unless were piping the output to another program
if [ -t 1 ]; then
echo ""; # newline
fi
}
# Decode \x{ABCD}-style Unicode escape sequences
unidecode() {
perl -e "binmode(STDOUT, ':utf8'); print \"$*\""
# print a newline unless were piping the output to another program
if [ -t 1 ]; then
echo ""; # newline
fi
}
# Get a characters Unicode code point
codepoint() {
perl -e "use utf8; print sprintf('U+%04X', ord(\"$*\"))"
# print a newline unless were piping the output to another program
if [ -t 1 ]; then
echo ""; # newline
fi
}
# Get colors in manual pages
man() {
env \
LESS_TERMCAP_mb="$(printf '\e[1;31m')" \
LESS_TERMCAP_md="$(printf '\e[1;31m')" \
LESS_TERMCAP_me="$(printf '\e[0m')" \
LESS_TERMCAP_se="$(printf '\e[0m')" \
LESS_TERMCAP_so="$(printf '\e[1;44;33m')" \
LESS_TERMCAP_ue="$(printf '\e[0m')" \
LESS_TERMCAP_us="$(printf '\e[1;32m')" \
man "$@"
}
# a tool to test if a given date has passed
# give it any standard date string (next Fri, 4:19pm, etc.) and it returns
# a boolan if we are less than that date. Use to loop functions.
dateTest() {
[[ $(date +"%s" --date="$1") -gt $(date +"%s") ]]
}
# Test if a PID is running
pidTest() {
ps -p $1 &>/dev/null
[[ $? -eq 0 ]];
}
# Call 'tree' but pipe it through LS with color preservation
treep() { # short for tree pager
if [[ $# -gt 0 ]]; then
tree -C $* | less
else
tree -C | less
fi
}
ts() {
( # so we don't get stuck in that folder
cd "$HOME/Dropbox/Grad School/Writing/0000-dissertation"
grep -R "$1" *
)
}

15
logos/ram-1b.png.sh Normal file
View file

@ -0,0 +1,15 @@
#!/bin/bash
if [[ "$HOME" == "$PWD" ]]; then
echo """            ▄▄▄▄▄▄▄▄▄            
         ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄         
       ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄       
      ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄      
    ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄      
  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄      
  ▀▄▄▀▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄      
   ▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄       
  ▄▄▄▄▄ ▀▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄        
  ▄▄▄▄▄   ▀▀▄▄▄▄▄▄▄▄▄▀▀          
  ▄▄▀▄▄                          """
fi

15
logos/rem-1b.png.sh Normal file
View file

@ -0,0 +1,15 @@
#!/bin/bash
if [[ "$HOME" == "$PWD" ]]; then
echo """            ▄▄▄▄▄▄▄▄▄            
         ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄         
       ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄       
      ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄      
      ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄    
      ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄  
      ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▀▄▄▀  
       ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄   
        ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▀ ▄▄▄▄▄  
          ▀▀▄▄▄▄▄▄▄▄▄▀▀   ▄▄▄▄▄  
                          ▄▄▀▄▄  """
fi

View file

@ -0,0 +1,19 @@
#!/bin/bash
if [[ "$HOME" == "$PWD" ]]; then
echo """                     ▄▄▄                     
                 ▄▄▄▄▄▄▄▄▄▄▄                 
                ▄▄▄▄▄▄▄▄▄▄▄▄▄                
             ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄             
             ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄             
             ▀▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▀             
            ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄            
        ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄        
       ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄       
       ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄       
       ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄       
       ▄▄▄▄▄▄▄▄▄▄▄▄▄▀▀▀▀▀▄▄▄▄▄▄▄▄▄▄▄▄▄       
       ▀▄▄▄▄▄▄▄▄▄▄▄       ▄▄▄▄▄▄▄▄▄▄▄▀       
         ▀▄▄▄▄                 ▄▄▄▄▀         
                                             """
fi

14
misc.sh Normal file
View file

@ -0,0 +1,14 @@
#!/bin/bash
# random things I don't know how to sort
complete -cf sudo
# Include the autojump tool if it exists
if [[ -e /usr/share/autojump/autojump.sh ]]; then
. /usr/share/autojump/autojump.sh
fi
export LESS=R # colorize less output if we use a pipe
HISTSIZE=2000
HISTFILESIZE=10000

117
path_enviornment.sh Normal file
View file

@ -0,0 +1,117 @@
#!/bin/bash
#####################################################################
# If we have a path element, strip it then add it in the new location
#####################################################################
function testDirPathStripAdd() {
if [ -d "$1" ]; then
pathStripAdd "$1"
fi
}
function pathStripAdd() {
pathStrip "$1"
if [[ "$2" == "front" ]]; then
export PATH="${1}":"$PATH"
else
export PATH="$PATH":"${1}"
fi
}
function pathStrip() {
unset PATH2
# Iterate through each item of path.
# Keep items if they don't match argument $1
for p in ${PATH//:/ }; do
if [[ $p != *$1* ]] ; then
PATH2="${PATH2:-}":"$p"
#echo $PATH2
fi
done
export PATH="${PATH2:1}"
unset PATH2
}
#####################################################################
# A function to load enviornment variables
#####################################################################
function loadDirectory() {
DIR_EXPAND=$(readlink -f "$1")
if [ -d "$DIR_EXPAND" ] ; then
if [ -d "$DIR_EXPAND/bin" ] ; then
pathStripAdd "$DIR_EXPAND/bin" "$2"
fi
if [ -d "$DIR_EXPAND/lib" ] ; then
export LD_RUN_PATH="$DIR_EXPAND/lib:$LD_RUN_PATH"
export LD_LIBRARY_PATH="$DIR_EXPAND/lib:$LD_LIBRARY_PATH"
if [ -d "$DIR_EXPAND/lib/pkgconfig" ] ; then
export PKG_CONFIG_PATH="$DIR_EXPAND/lib/pkgconfig:$PKG_CONFIG_PATH"
fi
fi
if [ -d "$DIR_EXPAND/share/pkgconfig" ] ; then
export PKG_CONFIG_PATH="$DIR_EXPAND/share/pkgconfig:$PKG_CONFIG_PATH"
fi
if [ -d "$DIR_EXPAND/share/aclocal" ] ; then
export ACLOCAL_FLAGS="-I $DIR_EXPAND/share/aclocal $ACLOCAL_FLAGS"
fi
fi
}
###########
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
pathStripAdd "$HOME/bin" front
fi
if [ -d "$HOME/.bin" ] ; then
pathStripAdd "$HOME/.bin" front
fi
# And load the local directory
if [ -d "$HOME/.local" ] ; then
loadDirectory "$HOME/.local" front
# Set the data directory
if [ -d "$HOME/.local/share" ] ; then
export XDG_DATA_HOME="$HOME/.local/share"
fi
fi
# Load information that is in any extra random installed directory.
__LOAD_DIRS=(/opt/mate /opt/makemkv /opt/ffmpeg $HOME/.gem/ruby/2.5.0 /opt/icestorm)
for DIR_EXPAND in ${__LOAD_DIRS[*]}
do
loadDirectory $DIR_EXPAND
done
unset DIR_EXPAND __LOAD_DIRS
echo $PKG_CONFIG_PATH
echo $LD_RUN_PATH
echo $LD_LIBRARY_PATH
# CLEAN these variables
__VAR_PTR_LST=(PKG_CONFIG_PATH LD_RUN_PATH LD_LIBRARY_PATH)
for __VAR_PTR in ${__VAR_PTR_LST[*]}
do
# get the value in the pointer
eval __VAR_VAL=\$$__VAR_PTR
if [ ${#__VAR_VAL} -gt 0 ]; then
# Strip ending : or leading : if exists.
if [ ${__VAR_VAL: -1} == ":" ]; then
__VAR_VAL=${__VAR_VAL:0:-1}
fi
if [ ${__VAR_VAL:0:1} == ":" ]; then
__VAR_VAL=${__VAR_VAL:1}
fi
while [[ $__VAR_VAL == *"::"* ]]; do
__VAR_VAL=${__VAR_VAL/::/:}
done
while [[ $__VAR_VAL == *"/:"* ]]; do
__VAR_VAL=${__VAR_VAL/\/:/:}
done
# save the cleaned result
eval $__VAR_PTR=$__VAR_VAL
#echo $__VAR_PTR "=" $__VAR_VAL
fi
done
unset __VAR_PTR_LST __VAR_PTR __VAR_VAL

82
ps1.sh Normal file
View file

@ -0,0 +1,82 @@
#!/bin/bash
### Path Mangling Functions ####
function __currentDirTest() {
if [[ $# -eq 1 ]]; then # normally just test active directory
if [[ "$PWD" == "${1}"* ]]; then
echo 1
else
echo 0
fi
else # this allows for testing directory suffixes
DIR_LOC=$(echo "${PWD#${1}}" | cut -d/ -f1)
if [[ "$DIR_LOC" == *"${2}"* ]]; then
echo 1
else
echo 0
fi
fi
}
function __smbGVFSReplace() {
local prefix_testing='/run/user/'$(id -u)'/gvfs/smb-share:server='
local gvfs_pfx='/run/user/'$(id -u)'/gvfs'
if [[ $(__currentDirTest "$HOME") -eq 1 ]]; then
echo $(__replacePathStr "$HOME" '\~')
elif [[ $(__currentDirTest $gvfs_pfx'/smb-share:server=') -eq 1 ]]; then
local smb_match='smb-share:server=\([^,]*\),share=\([^/,]\+\)'
if [[ $(__currentDirTest $gvfs_pfx'/smb-share:server=' ',user=') -eq 1 ]]; then
echo $(__replacePathStr $gvfs_pfx'/'$smb_match',user=\([^,/]*\)\([^/]*\)' 'gvfs:\1=>\3@\2')
else
echo $(__replacePathStr $gvfs_pfx'/'$smb_match 'gvfs:\1=>\2')
fi
else
echo $PWD
fi
}
function __replacePathStr() {
__SEARCH=$(echo "$1" | sed 's_/_\\/_g')
__REPLACE=$(echo "$2" | sed 's_/_\\/_g')
echo $PWD | sed "s/${__SEARCH}/${__REPLACE}/g"
}
# Colored hostname special stuff for the Rem/Ram boxes
COLOR_RST='\[\e[39m\]'
ULINE='\[\e[4m\]'
ULINE_RST='\[\e[24m\]'
# Special Hostnames
if [[ "$(hostname)" == "Ram-the-Red" || "$(hostname)" == "Rem-the-Blue" ]]; then
# These get COLOR-normal-COLOR formating
COLOR_RST_ESC='\\[\\033[39m\\]'
if [[ "$(hostname)" == "Ram-the-Red" ]]; then
COLOR='\\[\\033[31m\\]' # Ram Red
else
COLOR='\\[\\033[34m\\]' # Rem Blue
fi
alt_hostname="${ULINE}$(uname -n | sed "s_\(Ram\|Red\|Rem\|Blue\)_${COLOR}\1${COLOR_RST_ESC}_g")${ULINE_RST}"
elif [[ "$(hostname)" == "pino" ]]; then
# Primitive COLOR hostnames
COLOR_NORM='\[\e[35m\]' # Pino (purple)
alt_hostname="${ULINE}${COLOR_NORM}$(uname -n)${COLOR_RST}${ULINE_RST}"
elif [[ "$(hostname)" == "Batou" ]]; then
COLOR_NORM='\[\e[1;33m\]' # Batou (Yellow)
alt_hostname="${ULINE}${COLOR_NORM}$(uname -n)${COLOR_RST}${ULINE_RST}"
else
# And the rest of the plebs get Green.
alt_hostname="\h"
fi
# Flip this flag to disable samba path substition.
if [[ 1 -eq 0 ]]; then
export PS1="\[\e[01;32m\]\u\[\e[00m\]@\[\e[01;32m\]${alt_hostname}"
export PS1+="\[\e[01;34m\] \w \\$\[\e[00m\] "
else
export PS1="\[\e[01;32m\]\u\[\e[00m\]@\[\e[01;32m\]${alt_hostname}"
export PS1+="\[\e[01;34m\] \$(__smbGVFSReplace) \\$\[\e[00m\] "
fi

3
reboot_msg.sh Normal file
View file

@ -0,0 +1,3 @@
#!/bin/bash
# Just throw a message out to the world if we're expecting to reboot soon.
if [[ -e /var/run/reboot-required ]]; then echo "Waiting on reboot."; fi