Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 172 additions & 0 deletions bash/lib/_remind.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
r_init() {
r_HELP=""
}


## ---------
## FILES
## ---------

r_files() {
files_HELP=(
"FILES"
"--------"
"topfiles [dir] - finds the largest files in the directory provided (or current dir if not specified)"
"topdirs - finds largest directories on the system"
)
for (( i=0; i<${#files_HELP[@]}; i++ ));
do
r_HELP+="${files_HELP[$i]}\\n";
done
}

## ---------
## PROCESSES
## ---------

r_processes() {
process_HELP=(
"PROCESSES"
"--------"
"findpid <name> - finds the process id the process containig <name>"
"pid <process_id> - returns process info about <process_id> specified"
""
"memhogs - see processes ranked by memory usage"
"cpuhogs - see processes ranked by cpu usage"
""
"my_ps - see list of ALL processes under my user"
)
for (( i=0; i<${#process_HELP[@]}; i++ ));
do
r_HELP+="${process_HELP[$i]}\\n";
done
}

## ---------
## NETWORK
## ---------

r_network() {
net_HELP=(
"NETWORK"
"--------"
"myip - returns the external ip address our LAN is using"
"myiip - returns the internal network ip address this computer is using"
"netexp - ping the modem to see ip addresses of other computers on the network"
""
"findport - find process id using port"
"openports - list all open ports"
"suopenports - list all open ports (visible to super user)"
""
"users - list currently connected users to this computer"
)

for (( i=0; i<${#net_HELP[@]}; i++ ));
do
r_HELP+="${net_HELP[$i]}\\n";
done
}


r_install() {
install_HELP=(
"INSTALLATION"
"-----"
)

install_HELP+=(
"yum list installed - view installed packages"
"sudo yum update -v - update packages and yum"
)

for (( i=0; i<${#install_HELP[@]}; i++ ));
do
r_HELP+="${install_HELP[$i]}\\n";
done
}

r_search() {
search_HELP=(
"SEARCH"
"------"
"grep <term> <file> - print lines matching <term> in <file>"
"grep -v <term> - print lines without <term>"
"grep -r <term> <dir> - print lines in files inside <dir> (recursively)"
""
"sed -n '/abc/p' - print lines that contain abc"
"sed 's/old-text/new-text/g' - replace all instances of 'old-text' with 'new-text'"
"sed -e '/FOO/s/love/sick/' - replace 'love' with 'sick' if line contains 'FOO'"
""
"awk '{print \$1,\$4}' - Print the 1st and 4th word"
"awk '{print NR,\$0}' - Print the line number, followed by the whole row"
"awk '{ if (NF > max) max = NF; line=\$0 } END { print line }' - Print line with most words"
"awk 'length(\$0) > 10' - Print lines that are larger than 10 characters "
""
"find <path> -name '<pattern>' - find file matching pattern recursively below path"
"qfind <file_name> - search directories below recursively for file with name = file_name"
)

for (( i=0; i<${#search_HELP[@]}; i++ ));
do
r_HELP+="${search_HELP[$i]}\\n";
done
}


function remind () {
INTRO=(
"which topic?"
"[A]ll"
"[f]iles"
"[p]rocesses"
"[n]etwork"
"[i]nstall"
"[s]earch"
)

clear
if [[ $1 == "" ]]; then
echo "${INTRO[*]}"
read response
else
response=$1;
fi

r_init
case $response in
A)
r_files
r_processes
r_network
r_install
r_search
;;
f)
r_files
;;
p)
r_processes
;;
n)
r_network
;;
i)
r_install
;;
s)
r_search
;;
esac


case $response in
A)
echo -e $r_HELP | less
;;
*)
echo -e $r_HELP
;;
esac
}
alias r\?=remind
alias \?=remind
47 changes: 2 additions & 45 deletions bash/my_profile
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ alias .5='cd ../../../../../'
alias .6='cd ../../../../../../'
alias ~="cd ~"

alias clsls="clear; ls"

alias clr="clear"
alias cls="clear"
alias c="clear"
Expand Down Expand Up @@ -240,49 +242,4 @@ alias inbox="/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --ne
# 9. HELPER FUNCTIONS
# ---------------------------------------

## based on https://coderwall.com/p/pn8f0g/show-your-git-status-and-branch-in-color-at-the-command-prompt
function git_branch {
local git_status="$(git status 2> /dev/null)"
local on_branch="On branch ([^${IFS}]*)"
local on_commit="HEAD detached at ([^${IFS}]*)"

if [[ $git_status != "" ]]; then
local branch_msg="(";
else
local branch_msg=" "
fi

if [[ $git_status =~ "Untracked files:" || $git_status =~ "Changes not staged for commit:" ]]; then
branch_msg+="> "
elif [[ $git_status =~ "" ]]; then
branch_msg+=""
fi

if [[ $git_status =~ $on_branch ]]; then
local branch=${BASH_REMATCH[1]}
branch_msg+="$branch"
elif [[ $git_status =~ $on_commit ]]; then
local commit=${BASH_REMATCH[1]}
branch_msg+="$commit"
fi

if [[ $git_status =~ "Your branch is ahead of" ]]; then
branch_msg+=" +"
local num=`git status | grep -o '[0-9]\+'`
branch_msg+="$num"
elif [[ $git_status =~ "" ]]; then
branch_msg+=""
fi

if [[ $git_status =~ "Changes to be committed:" ]]; then
branch_msg+="*"
elif [[ $git_status =~ "" ]]; then
branch_msg+=""
fi

if [[ $git_status != "" ]]; then
branch_msg+=")"
fi

echo "$branch_msg"
}
136 changes: 125 additions & 11 deletions bash/server_profile
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,20 +1,134 @@
# .bash_profile for servers (Displays the server name in the Command Prompt)

SERVER_NAME="Example Server Name"

# message on signout?
#

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# -------------------------------
# 1. ENVIRONMENT CONFIGURATION
# -------------------------------

# User specific environment and startup programs
## Set Path
##############

PATH=$PATH:$HOME/.local/bin:$HOME/bin
#?: will we do anything here?

export PATH
# Set Default Editor
# ------------------------------------------------------------
export EDITOR=/usr/bin/vim

## [\e] == esc character
## \a\ == bell character (between these sets the terminal title)
PS1="\[\e]0;(${SERVER_NAME}): \w\a\][\u@\h \w] \$"
# My Scripts

CUR_DIR=$(dirname "$BASH_SOURCE[0]")
export PATH="$PATH:$CUR_DIR/../scripts"

source $CUR_DIR/lib/_remind.sh

## Set PROMPT
##############

# start underline and print current directory
PS1="$(tput sgr 0 1) \`pwd\`"

# add spaces based on width
PS1+="\`printf '%*s' \$(max 1 \$(( \$((\$(tput cols) - 15)) - \$( pwd | wc -m | grep -o '[0-9]\+') - \$(gitstatus | wc -m | grep -o '[0-9]\+') - $(whoami | wc -m | grep -o '[0-9]\+') - $(hostname | wc -m | grep -o '[0-9]\+')))) ''\`"

# add git status and stop underline
PS1+="\`gitstatus\`$(tput sgr0)| "

# print user and hostname
PS1+="\u @ \h\n| =>"
export PS1
export PS2="|>"


# -------------------------------
# 2. TERMINAL ALIASES AND FUNCTIONS
# -------------------------------
alias cls=clear
alias clsls="cls; ls"

alias ls="ls -FGlAhp"
alias less="less -FSRXc"

function mcd()
{
mkdir $1;
cd $1;
}

alias ivm=vim

# ---------------------------
# 3. FILE AND FOLDER MANAGEMENT
# ---------------------------

topfiles() {
du -a "$@" 2> /dev/null | sort -n -r | head -n 10
}

# ---------------------------
# 4. SEARCHING
# ---------------------------

alias qfind="find . -name "


# ---------------------------
# 5. PROCESS MANAGEMENT
# ---------------------------

findPid () { lsof -t -c "$@" ; }

alias memhogstop='top -l 1 -o rsize | head -20'
alias memhogsps='ps wwaxm -o pid,stat,vsize,rss,time,comm | head -10'
alias memhogs=memhogsps

alias cpuhogs='ps wwaxr -o pid,stat,%cpu,time,comm | head -10'

my_ps() { ps $@ -u $USER -o pid,%cpu,%mem,start,time,bsdtime,comm ; }

alias users='cat /etc/passwd | cut -d ":" -f 1'

# ---------------------------
# 6. NETWORKING
# ---------------------------

alias myip='dig +short myip.opendns.com @resolver1.opendns.com'

myiip () {
local ip info
ip=""
i=0
while [[ -z $ip && $i < 10 ]]; do
ip=`ifconfig eth${i} | grep -e "inet" | awk '{print $2}'`
if [[ ! -z $ip ]]; then
break
fi
i=$((i + 1))
done
echo $ip
}

netexp () {
echo "Pinging Network..."
ping `myiip | sed 's/\([0-9]*\.[0-9]*\.[0-9]*\.\)[0-9]*/\1255/'` -c5 -q > /dev/null
eval 'arp -a'
}


findPort () {
lsof -nP -iTCP:$1 | grep LISTEN ;
}

alias netcons="lsof -i"
alias openports="lsof -i | grep LISTEN"
alias suopenports="sudo lsof -i | grep LISTEN"
alias sudopenports=suopenports

alias on="w -h"

# ---------------------------------------
# 7. HELPER FUNCTIONS
# ---------------------------------------

Loading