From 517465f646c9c08029c8950b29baaf92c296b221 Mon Sep 17 00:00:00 2001 From: Devlin Date: Fri, 29 Apr 2022 03:29:15 +0000 Subject: [PATCH 1/8] started on motd and server profile --- bash/lib/_remind.sh | 171 ++++++++++++++++++++++++++++++++++++++++++++ bash/my_profile | 45 ------------ bash/server_profile | 135 +++++++++++++++++++++++++++++++--- motd.sh | 129 +++++++++++++++++++++++++++++++++ 4 files changed, 424 insertions(+), 56 deletions(-) create mode 100644 bash/lib/_remind.sh mode change 100644 => 100755 bash/server_profile create mode 100755 motd.sh diff --git a/bash/lib/_remind.sh b/bash/lib/_remind.sh new file mode 100644 index 0000000..b461e41 --- /dev/null +++ b/bash/lib/_remind.sh @@ -0,0 +1,171 @@ +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)" + ) + for (( i=0; i<${#files_HELP[@]}; i++ )); + do + r_HELP+="${files_HELP[$i]}\\n"; + done +} + +## --------- +## PROCESSES +## --------- + +r_processes() { + process_HELP=( + "PROCESSES" + "--------" + "findpid - finds the process id the process containig " + "pid - returns process info about 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 - print lines matching in " + "grep -v - print lines without " + "grep -r - print lines in files inside (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 -name '' - find file matching pattern recursively below path" + "qfind - 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 diff --git a/bash/my_profile b/bash/my_profile index 1886a3e..4f9588b 100644 --- a/bash/my_profile +++ b/bash/my_profile @@ -240,49 +240,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" -} diff --git a/bash/server_profile b/bash/server_profile old mode 100644 new mode 100755 index d2954ab..a198873 --- a/bash/server_profile +++ b/bash/server_profile @@ -1,20 +1,133 @@ # .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 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 +# --------------------------------------- diff --git a/motd.sh b/motd.sh new file mode 100755 index 0000000..b9590aa --- /dev/null +++ b/motd.sh @@ -0,0 +1,129 @@ +#! /bin/bash + + +TREEHOUSE=( +" vvv^^^^vvvv" +" vvvvvv^^vvvvv^^vvvv" +" vvvvvvvv^^^^^^^^^^^^^vvvvv^^^vvvv" +" vvvvvvvv^^^v^^^vvvvvv^^vvvvvvvv^^^vvvvvvv" +" ^vvvvvvvvv^^^^vvvvvv^^^^^^vvvvvvvv^^^vvvvv^v" +" vv^^vvv^^^vvvvvv^vvvvv^vvvvvv^^^vvvvvvv^^vv^" +" vv^vvvv^^vvv^^vvvvv^^vvvvv^v##vvv^vvv^^vvvv^v" +"^vvvv^^vvvvvv^vv^vvv^^^^^^______#^^^vvvvv^^^^" +" ^^vvvvv^^vvvvvvvvv^^^^/\@@@@@@\\#vvvv^^^" +" ^^vvvv^^^^^vvvv/__\@@@@@@\^vvvv^v" +" ;^^vvvvvvv/____\@@@@@@\\vvvvvvv" +" ; \_ ^\|[ -:] ||--| | _/^^" +" ; \ |[ :] ||_/| |/" +" ; \\\\||___:]______/" +" ; \ ;=; /" +" ; | ;=;|" +" ; () ;=;|" +" (() || ;=;|" +" / / \;=;\\" +) + +MSG=( + "" +) +OG_LENGTH=${#MSG[*]} + +# Fetch Weather +RES=$(curl "https://wttr.in/Portland?0" 2> /dev/null) +OLDIFS=$IFS +IFS=$'\n' +WTTR=($RES) +IFS=$OLDIFS + +# Add Weather to top of motd +wttr_length=${#WTTR[@]} +for (( i=0; i<${wttr_length}; i++ )); +do + MSG[$((${i}+$OG_LENGTH))]+=${WTTR[$i]} +done + + +HOST=$(hostname) +GROUP_COUNT=$(cat /etc/group | wc -l) +USER_COUNT=$(cat /etc/passwd | wc -l) +USERS=$(w -h | wc -l) + +CRONS=$(crontab -l | grep -e '^[^#]' | wc -l) +PATH_SIZE=$(echo $PATH | tr ':' '\n' | wc -l) + +OIFS=$IFS; +IFS=$'\n' +HISTORY=($(cat ~/.bash_history | tail -3)) +IFS=$OIFS; + +HISTORY_DIRS=($(cat ~/.bash_history | grep '^cd' | cut -d' ' -f2 | tail -3)) + +# TODO: WIP on custom message (server details/stats) +# mounted drives +# size of disk +# unique apps/dirs +# [x] users/groups +# [x] crontabs +# [..] history +# [..] path +# [..] current users/ips/ports/connections + + +MSG+=( + "" + " (defined in /etc/profile.d/motd.sh)" + "|----------------------------------------------|" + "| host: ${HOST}" + "| users: ${USER_COUNT} | groups: ${GROUP_COUNT} | online: ${USERS} | crons: ${CRONS}" + "| pathsize: ${PATH_SIZE}" + "|- (history) -- cmd ----------- dirs ----------|" + "| $(echo -e ${HISTORY[2]:0:20})" + "| $(echo -e ${HISTORY[1]:0:20})" + "| $(echo -e ${HISTORY[0]:0:20})" + "|----------------------------------------------|" +) + +length=${#MSG[@]} +start=$((${length}-4)) +end=$((${length}-1)) +for (( j=$start; j<${end}; j++ )); +do + i=$((${length}-${j}-3)) + + # Find Visible Character Count + CHAR=$(echo -e ${MSG[$j]}| sed "s/$(echo -e "\e")[^m]*m//g" | wc -c) + WHITE_SPACE=$(echo -e ${MSG[$j]} | tr -d -c ' ') + + SIZE=$((25-$CHAR-${#WHITE_SPACE})) + MSG[$j]+=$(printf ' %.0s' $(seq 1 $SIZE)) + MSG[$j]+="| ${HISTORY_DIRS[$i]:0:20}" +done + +if [[ $(hostname) == "dev-junk.com" ]]; then + # If width of terminal > 100 characters (add treehouse to motd) + if [ $(tput cols) -gt 93 ]; then + # Loop over treehouse and add to printed message + length=${#TREEHOUSE[@]} + for (( j=0; j<${length}; j++ )); + do + # Find Visible Character Count + CHAR=$(echo -e ${MSG[$j]} | sed "s/$(echo -e "\e")[^m]*m//g" | wc -c) + + # Find Visible White Space + if [ $j -le $wttr_length ] || [ $j -ge $start ]; then + WHITE_SPACE=$(echo -e "${MSG[$j]}" | tr -d -c ' ') + else + WHITE_SPACE=$(echo -e "${MSG[$j]}" | sed 's/[^ ].*$//') + fi + SIZE=$((50-$CHAR-${#WHITE_SPACE})) + MSG[$j]+=$(printf ' %.0s' $(seq 1 $SIZE)) + + # Add Tree House + MSG[$j]+=${TREEHOUSE[$j]} + done + fi +fi + +printf -v PRINT "%s\n" "${MSG[@]}" +echo "$PRINT" + From 4743dd92803f87c4cdc0836ba3b71cc8c09c65cb Mon Sep 17 00:00:00 2001 From: Devlin Date: Fri, 29 Apr 2022 05:35:43 +0000 Subject: [PATCH 2/8] fix char count --- motd.sh | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/motd.sh b/motd.sh index b9590aa..13acba7 100755 --- a/motd.sh +++ b/motd.sh @@ -77,9 +77,9 @@ MSG+=( "| users: ${USER_COUNT} | groups: ${GROUP_COUNT} | online: ${USERS} | crons: ${CRONS}" "| pathsize: ${PATH_SIZE}" "|- (history) -- cmd ----------- dirs ----------|" - "| $(echo -e ${HISTORY[2]:0:20})" - "| $(echo -e ${HISTORY[1]:0:20})" - "| $(echo -e ${HISTORY[0]:0:20})" + "| ${HISTORY[2]:0:20}" + "| ${HISTORY[1]:0:20}" + "| ${HISTORY[0]:0:20}" "|----------------------------------------------|" ) @@ -91,11 +91,15 @@ do i=$((${length}-${j}-3)) # Find Visible Character Count - CHAR=$(echo -e ${MSG[$j]}| sed "s/$(echo -e "\e")[^m]*m//g" | wc -c) - WHITE_SPACE=$(echo -e ${MSG[$j]} | tr -d -c ' ') + CHAR=$(echo -n -e ${MSG[$j]}| sed "s/$(echo -n -e "\e")[^m]*m//g" | tr -d ' ' | wc -c) + + # Find Visible White Space + WHITE_SPACE=$(echo -n -e ${MSG[$j]} | tr -d -c ' ') - SIZE=$((25-$CHAR-${#WHITE_SPACE})) - MSG[$j]+=$(printf ' %.0s' $(seq 1 $SIZE)) + # Pad end with spaces + PADDING=$((25-$CHAR-${#WHITE_SPACE})) + MSG[$j]+=$(printf ' %.0s' $(seq 1 $PADDING)) + MSG[$j]+="| ${HISTORY_DIRS[$i]:0:20}" done @@ -107,19 +111,19 @@ if [[ $(hostname) == "dev-junk.com" ]]; then for (( j=0; j<${length}; j++ )); do # Find Visible Character Count - CHAR=$(echo -e ${MSG[$j]} | sed "s/$(echo -e "\e")[^m]*m//g" | wc -c) + CHAR=$(echo -n -e ${MSG[$j]} | sed "s/$(echo -n -e "\e")[^m]*m//g" | tr -d ' ' | wc -c) # Find Visible White Space - if [ $j -le $wttr_length ] || [ $j -ge $start ]; then - WHITE_SPACE=$(echo -e "${MSG[$j]}" | tr -d -c ' ') - else - WHITE_SPACE=$(echo -e "${MSG[$j]}" | sed 's/[^ ].*$//') - fi - SIZE=$((50-$CHAR-${#WHITE_SPACE})) - MSG[$j]+=$(printf ' %.0s' $(seq 1 $SIZE)) + WHITE_SPACE=$(echo -n -e "${MSG[$j]}" | tr -d -c ' ' ) + + # Pad end with whitespace + PADDING=$((50-$CHAR-${#WHITE_SPACE})) + MSG[$j]+=$(printf ' %.0s' $(seq 1 $PADDING)) # Add Tree House MSG[$j]+=${TREEHOUSE[$j]} + + #MSG[$j]=$(pad 50 ${MSG[$j} ${TREEHOUSE[$j]}) done fi fi From 0c8007243777f9b4e082c55a499e6313a0345601 Mon Sep 17 00:00:00 2001 From: Devlin Date: Tue, 23 Aug 2022 03:04:36 +0000 Subject: [PATCH 3/8] add more commands to remind" --- zsh/lib/_remind.zsh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/zsh/lib/_remind.zsh b/zsh/lib/_remind.zsh index 35e985d..0a140dd 100644 --- a/zsh/lib/_remind.zsh +++ b/zsh/lib/_remind.zsh @@ -13,6 +13,9 @@ r_files() { " FILES " "------- " "numFiles - count number of files in current directory" + "" + "du -a -d1 - show file size (depth=1) in current directoy or wherever passed" + "df -h - show size and amount of storage available on drives" ) if [[ "$OSTYPE" == "darwin"* ]]; then From 6dc6850f26e8282414ebd584f05910ba2be9e14a Mon Sep 17 00:00:00 2001 From: Devlin Date: Sun, 11 Dec 2022 23:11:55 +0000 Subject: [PATCH 4/8] update message of the day with disk size --- motd.sh | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/motd.sh b/motd.sh index 13acba7..4f188aa 100755 --- a/motd.sh +++ b/motd.sh @@ -2,14 +2,16 @@ TREEHOUSE=( -" vvv^^^^vvvv" -" vvvvvv^^vvvvv^^vvvv" -" vvvvvvvv^^^^^^^^^^^^^vvvvv^^^vvvv" -" vvvvvvvv^^^v^^^vvvvvv^^vvvvvvvv^^^vvvvvvv" -" ^vvvvvvvvv^^^^vvvvvv^^^^^^vvvvvvvv^^^vvvvv^v" -" vv^^vvv^^^vvvvvv^vvvvv^vvvvvv^^^vvvvvvv^^vv^" -" vv^vvvv^^vvv^^vvvvv^^vvvvv^v##vvv^vvv^^vvvv^v" -"^vvvv^^vvvvvv^vv^vvv^^^^^^______#^^^vvvvv^^^^" +" ()" +" ()" +" vvv^^^()vvvv" +" vvvvvv^^v()vvv^^vvvv" +" vvvvvvvv^^^^^^^^^^^^^()vvv^^^vvvv" +" vvvvvvvv^^^v^^^vvvvvv^^vvv()vvvv^^^vvvvvvv" +" ^vvvvvvvvv^^^^vvvvvv^^^()^vvvvvvvv^^^vvvvv^v" +" vv^^vvv^^^vvvvvv^vvvvv^vvv()v^^^vvvvvvv^^vv^" +" vv^vvvv^^vvv^^vvvvv^^vvvvv^()#vvv^vvv^^vvvv^v" +"^vvvv^^vvvvvv^vv^vvv^^^^^^__[]__#^^^vvvvv^^^^" " ^^vvvvv^^vvvvvvvvv^^^^/\@@@@@@\\#vvvv^^^" " ^^vvvv^^^^^vvvv/__\@@@@@@\^vvvv^v" " ;^^vvvvvvv/____\@@@@@@\\vvvvvvv" @@ -51,6 +53,8 @@ USERS=$(w -h | wc -l) CRONS=$(crontab -l | grep -e '^[^#]' | wc -l) PATH_SIZE=$(echo $PATH | tr ':' '\n' | wc -l) +HD_SIZE=$(sudo du -h / 2>/dev/null | grep -P "^\d.?\dG" | sort -n | tail -n1) + OIFS=$IFS; IFS=$'\n' HISTORY=($(cat ~/.bash_history | tail -3)) @@ -76,6 +80,7 @@ MSG+=( "| host: ${HOST}" "| users: ${USER_COUNT} | groups: ${GROUP_COUNT} | online: ${USERS} | crons: ${CRONS}" "| pathsize: ${PATH_SIZE}" + "| disk size: ${HD_SIZE}" "|- (history) -- cmd ----------- dirs ----------|" "| ${HISTORY[2]:0:20}" "| ${HISTORY[1]:0:20}" @@ -104,8 +109,11 @@ do done if [[ $(hostname) == "dev-junk.com" ]]; then + # if no term then do nothing + if [ -z $TERM ]; then + echo "No Terminal" # If width of terminal > 100 characters (add treehouse to motd) - if [ $(tput cols) -gt 93 ]; then + elif [ $(tput cols) -gt 93 ]; then # Loop over treehouse and add to printed message length=${#TREEHOUSE[@]} for (( j=0; j<${length}; j++ )); From cd7389e4022ee2c05dbebf5c216def09200b9dca Mon Sep 17 00:00:00 2001 From: Devlin Date: Sun, 11 Dec 2022 23:51:18 +0000 Subject: [PATCH 5/8] add topdirs script --- bash/lib/_remind.sh | 1 + scripts/topdirs | 16 ++++++++++++++++ zsh/lib/_remind.zsh | 1 + 3 files changed, 18 insertions(+) create mode 100755 scripts/topdirs diff --git a/bash/lib/_remind.sh b/bash/lib/_remind.sh index b461e41..6db02a2 100644 --- a/bash/lib/_remind.sh +++ b/bash/lib/_remind.sh @@ -12,6 +12,7 @@ r_files() { "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 diff --git a/scripts/topdirs b/scripts/topdirs new file mode 100755 index 0000000..ad65656 --- /dev/null +++ b/scripts/topdirs @@ -0,0 +1,16 @@ +#! /bin/bash + +GIG_FOLDERS=$(sudo du -h / 2>/dev/null | grep -P "^\d.?\dG" | sort -n | tail -n30) + +UNIQUE=() +while IFS= read -r line; do + DIR_NAME=$(echo "$line" | cut -d $'\t' -f 2) + COUNT=$(echo "$GIG_FOLDERS" | grep -o "$DIR_NAME" | wc -l) + if [ $COUNT -eq 1 ]; then + UNIQUE=("${UNIQUE[@]}" "$line") + fi + #echo ${LINE#\d*G} +done <<< "$GIG_FOLDERS" + +printf "%s\n" "${UNIQUE[@]}" + diff --git a/zsh/lib/_remind.zsh b/zsh/lib/_remind.zsh index 0a140dd..1ae396a 100644 --- a/zsh/lib/_remind.zsh +++ b/zsh/lib/_remind.zsh @@ -13,6 +13,7 @@ r_files() { " FILES " "------- " "numFiles - count number of files in current directory" + "topdirs - lists the largest directories on the machine" "" "du -a -d1 - show file size (depth=1) in current directoy or wherever passed" "df -h - show size and amount of storage available on drives" From 9ce3bf438fba4c46ef2318f2c9e3c3a5d96d69a1 Mon Sep 17 00:00:00 2001 From: Devlin Date: Sun, 11 Dec 2022 23:52:24 +0000 Subject: [PATCH 6/8] clean up remind --- zsh/lib/_remind.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zsh/lib/_remind.zsh b/zsh/lib/_remind.zsh index 1ae396a..3d2b09e 100644 --- a/zsh/lib/_remind.zsh +++ b/zsh/lib/_remind.zsh @@ -16,7 +16,7 @@ r_files() { "topdirs - lists the largest directories on the machine" "" "du -a -d1 - show file size (depth=1) in current directoy or wherever passed" - "df -h - show size and amount of storage available on drives" + "df -h - show size and amount of storage available on mounted disks" ) if [[ "$OSTYPE" == "darwin"* ]]; then From 516b8d00a3b7e24a2989f2ea5ef349d84d0c4e53 Mon Sep 17 00:00:00 2001 From: Devlin Date: Mon, 12 Dec 2022 00:32:07 +0000 Subject: [PATCH 7/8] add more info to motd --- motd.sh | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/motd.sh b/motd.sh index 4f188aa..1b22824 100755 --- a/motd.sh +++ b/motd.sh @@ -53,6 +53,7 @@ USERS=$(w -h | wc -l) CRONS=$(crontab -l | grep -e '^[^#]' | wc -l) PATH_SIZE=$(echo $PATH | tr ':' '\n' | wc -l) + HD_SIZE=$(sudo du -h / 2>/dev/null | grep -P "^\d.?\dG" | sort -n | tail -n1) OIFS=$IFS; @@ -79,8 +80,8 @@ MSG+=( "|----------------------------------------------|" "| host: ${HOST}" "| users: ${USER_COUNT} | groups: ${GROUP_COUNT} | online: ${USERS} | crons: ${CRONS}" - "| pathsize: ${PATH_SIZE}" - "| disk size: ${HD_SIZE}" + "| pathsize: ${PATH_SIZE} ( 'compgen -c' to view )" + "| disk size: $( echo ${HD_SIZE%/} | xargs) ( 'topdirs to view )" "|- (history) -- cmd ----------- dirs ----------|" "| ${HISTORY[2]:0:20}" "| ${HISTORY[1]:0:20}" @@ -139,3 +140,21 @@ fi printf -v PRINT "%s\n" "${MSG[@]}" echo "$PRINT" + + +# TODO: Abstract this +pad() { + # Find Visible Character Count + CHAR=$(echo -n -e $2 | sed "s/$(echo -n -e "\e")[^m]*m//g" | tr -d ' ' | wc -c) + + # Find Visible White Space + WHITE_SPACE=$(echo -n -e $2 | tr -d -c ' ') + + # Pad end with spaces + PADDING=$(($1-$CHAR-${#WHITE_SPACE})) + + echo "$(printf ' %.0s' $(seq 1 $PADDING))| $3" +} + +# pad "20" "test" 'test34' + From 5ab481161f7479594a5cbc7a87cc79300d88ee28 Mon Sep 17 00:00:00 2001 From: Devlin Date: Fri, 13 Jan 2023 03:15:05 +0000 Subject: [PATCH 8/8] add cls and make motd not run as long --- bash/my_profile | 2 ++ bash/server_profile | 1 + motd.sh | 2 +- zsh/lib/alias_osx.zsh | 2 ++ 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/bash/my_profile b/bash/my_profile index 4f9588b..080b17e 100644 --- a/bash/my_profile +++ b/bash/my_profile @@ -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" diff --git a/bash/server_profile b/bash/server_profile index a198873..8c8bba0 100755 --- a/bash/server_profile +++ b/bash/server_profile @@ -46,6 +46,7 @@ export PS2="|>" # 2. TERMINAL ALIASES AND FUNCTIONS # ------------------------------- alias cls=clear +alias clsls="cls; ls" alias ls="ls -FGlAhp" alias less="less -FSRXc" diff --git a/motd.sh b/motd.sh index 1b22824..46e2a74 100755 --- a/motd.sh +++ b/motd.sh @@ -54,7 +54,7 @@ CRONS=$(crontab -l | grep -e '^[^#]' | wc -l) PATH_SIZE=$(echo $PATH | tr ':' '\n' | wc -l) -HD_SIZE=$(sudo du -h / 2>/dev/null | grep -P "^\d.?\dG" | sort -n | tail -n1) +#HD_SIZE=$(sudo du -hd1 / 2>/dev/null | grep -P "^\d.?\dG" | sort -n | tail -n1) OIFS=$IFS; IFS=$'\n' diff --git a/zsh/lib/alias_osx.zsh b/zsh/lib/alias_osx.zsh index c7af555..c1245bd 100644 --- a/zsh/lib/alias_osx.zsh +++ b/zsh/lib/alias_osx.zsh @@ -5,6 +5,8 @@ alias clr="clear" alias cls="clear" alias c="clear" +alias clsls="cls; ls" + ## File Management alias finder="open -a Finder ./"