Last active
January 10, 2026 03:56
-
-
Save mshafeeqkn/794d26711a7201552354493c7a2e77ee to your computer and use it in GitHub Desktop.
The PS1 variable for bashrc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| parse_git_branch() { | |
| _branch=$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/') | |
| _branch="$_branch" | |
| echo $_branch | |
| } | |
| export PS1="\[\033[38;5;42m\]\u@\h\[\033[00m\]:\[\033[38;5;39m\]\W\[\033[38;5;198m\]\$(parse_git_branch)\[\033[00m\]$ " | |
| go() { | |
| local dir="$1" | |
| if [ -z "$dir" ]; then | |
| echo "Usage: go <dir-name>" | |
| return 1 | |
| fi | |
| # Find all directories matching the name | |
| mapfile -t dirs < <(find . -type d -name "$dir" 2>/dev/null) | |
| if [ ${#dirs[@]} -eq 0 ]; then | |
| return 0 | |
| elif [ ${#dirs[@]} -eq 1 ]; then | |
| cd "${dirs[0]}" || { echo "Failed to cd"; return 1; } | |
| echo "Changed directory to: $(pwd)" | |
| return 0 | |
| fi | |
| # Multiple matches: list options | |
| echo "Found ${#dirs[@]} directories:" | |
| for i in "${!dirs[@]}"; do | |
| echo "$((i+1))) ${dirs[$i]}" | |
| done | |
| # Prompt user to choose | |
| read -p "Enter the number of the directory to cd into: " choice | |
| if [[ "$choice" =~ ^[0-9]+$ ]] && [ "$choice" -ge 0 ] && [ "$choice" -le ${#dirs[@]} ]; then | |
| cd "${dirs[$((choice-1))]}" || { echo "Failed to cd"; return 1; } | |
| echo "Changed directory to: $(pwd)" | |
| fi | |
| } | |
| govim() { | |
| local name="$1" | |
| if [ -z "$name" ]; then | |
| echo "Usage: govim <file-name>" | |
| return 1 | |
| fi | |
| # Find all files matching the name (glob-style; exact -name match) | |
| mapfile -t files < <(find . -type f -name "$name" 2>/dev/null) | |
| # If no exact-name matches, fall back to substring match with -path | |
| if [ ${#files[@]} -eq 0 ]; then | |
| # Escape special chars in $name for a safer substring search: | |
| # NOTE: find does not do regex here; this is a simple glob path match. | |
| mapfile -t files < <(find . -type f -path "*/$name*" 2>/dev/null) | |
| fi | |
| if [ ${#files[@]} -eq 0 ]; then | |
| # No matches at all | |
| return 0 | |
| elif [ ${#files[@]} -eq 1 ]; then | |
| # Single match: open directly | |
| local chosen="${files[0]}" | |
| local base="${chosen##*/}" # basename without spawning external processes | |
| # Update /tmp/.govim to keep only the basename, dedupe safely | |
| if [ -f /tmp/.govim ]; then | |
| # Remove any existing exact match of this basename | |
| # Use grep -Fx to match full line exactly; write to a temp, then move | |
| grep -Fvx -- "$base" /tmp/.govim > /tmp/.govim.tmp 2>/dev/null || true | |
| mv /tmp/.govim.tmp /tmp/.govim | |
| fi | |
| printf '%s\n' "$base" >> /tmp/.govim | |
| echo "$chosen" | |
| vim "$chosen" | |
| return $? | |
| fi | |
| # Multiple matches: list options | |
| echo "Found ${#files[@]} files:" | |
| for i in "${!files[@]}"; do | |
| printf "%2d) %s\n" $((i+1)) "${files[$i]}" | |
| done | |
| # Prompt user to choose | |
| local choice | |
| read -r -p "Enter the number of the file to open in vim: " choice | |
| # Validate: choice is numeric and within range (1..N) | |
| if [[ "$choice" =~ ^[0-9]+$ ]] && [ "$choice" -ge 1 ] && [ "$choice" -le ${#files[@]} ]; then | |
| local chosen="${files[$((choice-1))]}" | |
| local base="${chosen##*/}" | |
| # Update /tmp/.govim with basename only, dedupe | |
| if [ -f /tmp/.govim ]; then | |
| grep -Fvx -- "$base" /tmp/.govim > /tmp/.govim.tmp 2>/dev/null || true | |
| mv /tmp/.govim.tmp /tmp/.govim | |
| fi | |
| printf '%s\n' "$base" >> /tmp/.govim | |
| vim "$chosen" | |
| return $? | |
| else | |
| echo "Invalid choice." | |
| return 1 | |
| fi | |
| } | |
| jk() { | |
| JUNK_DIR=$HOME/.junk/ | |
| JUNK_ARGS="$@" | |
| if [ ! -d $JUNK_DIR ]; then | |
| mkdir $JUNK_DIR | |
| fi | |
| if [ "$1" = "-e" ]; then | |
| rm -rf $JUNK_DIR | |
| return | |
| fi | |
| echo "" | |
| for item in $@; do | |
| RAND=$(tr -dc a-z0-9 </dev/urandom | head -c 5; echo) | |
| if [ -d $item -o -f $item ]; then | |
| mv $item $JUNK_DIR/$item.$RAND | |
| echo -e "\033[0;32m$item junked\033[0m" | |
| else | |
| echo -e "\033[0;31m$item doesn't exist\033[0m" | |
| fi | |
| done | |
| echo "" | |
| } | |
| alias ifconfig="ip -c a s" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment