diff --git a/.bash_aliases b/.bash_aliases new file mode 100644 index 0000000..6d95b8b --- /dev/null +++ b/.bash_aliases @@ -0,0 +1,2 @@ +alias please='sudo $(fc -ln -1)' +alias resource='source ~/.bash_profile' diff --git a/.bash_functions b/.bash_functions new file mode 100644 index 0000000..4772fa3 --- /dev/null +++ b/.bash_functions @@ -0,0 +1,12 @@ +function mcd { + mkdir "$@" && cd $_ +} + +function rewind { + # cheeky hack + source rewind.sh "$HISTFILE" "$@" +} + +function download { + curl "$1" > "$2" +} diff --git a/.bash_profile b/.bash_profile new file mode 100644 index 0000000..e3c0e22 --- /dev/null +++ b/.bash_profile @@ -0,0 +1,3 @@ +[ -f ~/.bash_aliases ] && . ~/.bash_aliases +[ -f ~/.bash_functions ] && . ~/.bash_functions +export PS1='\[\033[0m\]\[\033[1;36m\]\w\[\033[0m\]\n: \$\u@\h; ' diff --git a/init.sh b/init.sh new file mode 100644 index 0000000..d866a98 --- /dev/null +++ b/init.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# set internal field separator, +# saving old one +OIFS="$IFS" +IFS=$'\n' + +MV="mv" +LN="ln" + +[[ -d ~/apt_stuff ]] || mkdir ~/apt_stuff + +if [[ "$PATH" != *"~/.cyber_bin"* ]]; then + # if script not run yet + PATH="$PATH:~/.cyber_bin" + mkdir ../.cyber_bin +fi + +for file in $(ls -A1 .bash_*); do + ${MV} "$file" ~ +done + +for file in $( + ls -1 | + egrep -vi \(init\|license\|readme\|git\) +); do + ${LN} "$file" "~/.cyber_bin/$file" +done + +[[ ! -f ~/.bashrc ]] && ${LN} ~/.bash_profile ~/.bashrc + +# push changes made to PATH +hash -r +source ~/.bash_profile + +# reset internal field separator +IFS="$OIFS" \ No newline at end of file diff --git a/rewind.sh b/rewind.sh new file mode 100644 index 0000000..5e89318 --- /dev/null +++ b/rewind.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +HISTFILE="$1"; shift 1 + +if [[ "$1" == "-f" ]]; then + # lazy getopt + TARGETFUNC="$2" + shift 2 +else + TARGETFUNC= +fi + +HEADLINES="${1:-1}" +FCLINES=$((HEADLINES + 1)) + +COMMANDS="$(fc -ln "-${FCLINES}" | head "-${HEADLINES}")" +# echo "$COMMANDS" + +if [[ -z "$TARGETFUNC" ]]; then + eval "$COMMANDS" +else + eval "function $TARGETFUNC { + $COMMANDS + }" +fi \ No newline at end of file