updated ubu bash
This commit is contained in:
@@ -0,0 +1,89 @@
|
|||||||
|
# ~/.bash_aliases
|
||||||
|
|
||||||
|
# --- Persistent SSH Agent ---
|
||||||
|
# Reuses existing agent across login sessions to prevent process bloat
|
||||||
|
SSH_ENV="$HOME/.ssh/agent_env"
|
||||||
|
|
||||||
|
function start_ssh_agent {
|
||||||
|
/usr/bin/ssh-agent -s | sed 's/^echo/#echo/' > "${SSH_ENV}"
|
||||||
|
chmod 600 "${SSH_ENV}"
|
||||||
|
. "${SSH_ENV}" > /dev/null
|
||||||
|
ssh-add ~/.ssh/github_rsa ~/.ssh/zippy-id_rsa ~/.ssh/zappy-id_root_rsa.key 2>/dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ -f "${SSH_ENV}" ]; then
|
||||||
|
. "${SSH_ENV}" > /dev/null
|
||||||
|
ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent > /dev/null || start_ssh_agent
|
||||||
|
else
|
||||||
|
start_ssh_agent
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --- Improved Search Functions (Requires ripgrep) ---
|
||||||
|
function fastfindtext() {
|
||||||
|
if [ -z "$1" ]; then
|
||||||
|
echo "Usage: fastfindtext <search_term>"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
# rg is superior for ISO workflows as it ignores hidden/binary/git-ignored files
|
||||||
|
rg -li "$1" \
|
||||||
|
-g '!{node_modules,bin,lib,lib64,dist,.git,__pycache__}' \
|
||||||
|
-g '!*.{o,pcap,so,a,tar,sql}'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Finding filenames
|
||||||
|
function f() { sudo find . -name "*$@*" 2>/dev/null; }
|
||||||
|
function fs() { sudo find . -iname "$@*" 2>/dev/null; }
|
||||||
|
function fe() { sudo find . -iname "*$@" 2>/dev/null; }
|
||||||
|
|
||||||
|
# --- Security & Networking ---
|
||||||
|
alias netconns='sudo ss -tunp'
|
||||||
|
alias openports='sudo ss -tulwn'
|
||||||
|
alias lsock='sudo lsof -i -P'
|
||||||
|
alias watchlogs='sudo tail -n 50 -f /var/log/syslog'
|
||||||
|
alias cpu_hogs='ps wwaxr -o pid,stat,%cpu,time,command | head -10'
|
||||||
|
|
||||||
|
# --- File & Directory Operations ---
|
||||||
|
alias h='history'
|
||||||
|
alias ll='ls -alF'
|
||||||
|
alias la='ls -A'
|
||||||
|
alias l='ls -CF'
|
||||||
|
alias disksize='df -kh'
|
||||||
|
alias dirsize='sudo du -h -d 1 . 2>/dev/null'
|
||||||
|
alias lsize='ls -lSrh --color | grep -v "^d"'
|
||||||
|
alias ldate='ls -ltr --color'
|
||||||
|
|
||||||
|
# --- Modern Workflow (Python/uv & Nginx) ---
|
||||||
|
alias uvr='uv run'
|
||||||
|
alias editnginx='vi /etc/nginx/sites-enabled/default'
|
||||||
|
alias restartnginx='nginx -t && systemctl reload nginx'
|
||||||
|
# Cat all enabled Nginx site configurations with headers
|
||||||
|
alias llnginx='for f in /etc/nginx/sites-enabled/*; do echo -e "\n\e[1;33m--- $f ---\e[0m"; cat "$f"; done'
|
||||||
|
|
||||||
|
# --- Git ---
|
||||||
|
alias gs='git status'
|
||||||
|
alias ga='git add .'
|
||||||
|
alias gc='git commit -m'
|
||||||
|
alias gp='git push'
|
||||||
|
|
||||||
|
# --- Miscellaneous ---
|
||||||
|
alias renew="source ~/.bashrc"
|
||||||
|
alias ccat="clear ; cat "
|
||||||
|
alias work="/root/bin/task-manager-curses/bin/python /root/bin/task-manager-curses/tasks.py --db /root/bin/task-manager-curses/tasks.db"
|
||||||
|
|
||||||
|
# Tree view function
|
||||||
|
function tree (){
|
||||||
|
pwd
|
||||||
|
ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Search for file and open in vi
|
||||||
|
vii() {
|
||||||
|
local file_path=$(find . -type f -name "$1" -print -quit)
|
||||||
|
if [[ -n "$file_path" ]]; then
|
||||||
|
vi "$file_path"
|
||||||
|
else
|
||||||
|
echo "File '$1' not found."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
alias lsgroups='uv run --project "/root/bin/lsgroup" --directory "$PWD" "/root/bin/lsgroup/lsgroup.py"'
|
||||||
|
|||||||
@@ -0,0 +1,106 @@
|
|||||||
|
# ~/.bashrc
|
||||||
|
|
||||||
|
# 1. Non-interactive shell check
|
||||||
|
[[ $- != *i* ]] && return
|
||||||
|
|
||||||
|
# 2. Path Helper (Prevents the "Mega-String" path pollution)
|
||||||
|
# This function only adds a directory if it isn't already there.
|
||||||
|
path_add() {
|
||||||
|
if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
|
||||||
|
export PATH="$1:$PATH"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Reset to a sane baseline then add your custom paths safely
|
||||||
|
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
||||||
|
path_add "$HOME/.local/bin"
|
||||||
|
path_add "/usr/local/sbin"
|
||||||
|
path_add "$HOME/bin"
|
||||||
|
|
||||||
|
path_add "$HOME/go/bin"
|
||||||
|
path_add "/snap/go/current/bin"
|
||||||
|
|
||||||
|
export SDKMAN_DIR="$HOME/.sdkman"
|
||||||
|
[[ -s "$SDKMAN_DIR/bin/sdkman-init.sh" ]] && source "$SDKMAN_DIR/bin/sdkman-init.sh"
|
||||||
|
|
||||||
|
# 3. History Settings (Security Audit Optimized)
|
||||||
|
HISTCONTROL=ignoredups:ignorespace
|
||||||
|
shopt -s histappend
|
||||||
|
HISTSIZE=10000
|
||||||
|
HISTFILESIZE=20000
|
||||||
|
export HISTTIMEFORMAT="%F %T " # Essential for incident response/forensics
|
||||||
|
PROMPT_COMMAND="history -a" # Save immediately after every command
|
||||||
|
|
||||||
|
# 4. Prompt & Shell Behavior
|
||||||
|
shopt -s checkwinsize
|
||||||
|
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
|
||||||
|
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
|
||||||
|
else
|
||||||
|
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 5. Completions
|
||||||
|
if [ -f /etc/bash_completion ]; then
|
||||||
|
. /etc/bash_completion
|
||||||
|
fi
|
||||||
|
complete -cf sudo
|
||||||
|
|
||||||
|
# 6. Load Aliases
|
||||||
|
if [ -f ~/.bash_aliases ]; then
|
||||||
|
. ~/.bash_aliases
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 7. NVM Setup (Loaded after Path to avoid conflicts)
|
||||||
|
export NVM_DIR="$HOME/.nvm"
|
||||||
|
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
|
||||||
|
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
|
||||||
|
|
||||||
|
# 8. Login Dashboard
|
||||||
|
echo -e "\n\e[1;32m--- Welcome Jared (Zappy) ---\e[0m"
|
||||||
|
echo "External IP: $(curl -4 -s --max-time 2 https://ifconfig.me || echo 'Offline')"
|
||||||
|
echo "Space left: $(df -h / | awk 'NR==2 {print $4}')"
|
||||||
|
echo -e "\n\e[1;34mQuick Commands:\e[0m"
|
||||||
|
|
||||||
|
# Filter: Remove internal bash functions (_) and NVM internals
|
||||||
|
(
|
||||||
|
alias | cut -d'=' -f1 | cut -d' ' -f2;
|
||||||
|
declare -F | cut -d' ' -f3 | grep -vE '^(_|nvm|path_add|start_ssh_agent|__)'
|
||||||
|
) | sort | xargs echo
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# --- Auto-activate Python .venv on cd ---
|
||||||
|
# Activates ./\.venv when present; deactivates when leaving that project tree.
|
||||||
|
# Safe for interactive shells only (your .bashrc already returns early for non-interactive).
|
||||||
|
|
||||||
|
_venv_auto_activate() {
|
||||||
|
local venv_path="$PWD/.venv"
|
||||||
|
|
||||||
|
# If we are already in a venv, but we've left its project directory, deactivate it.
|
||||||
|
if [[ -n "${VIRTUAL_ENV:-}" ]]; then
|
||||||
|
# If current dir is NOT under the venv's parent dir, deactivate.
|
||||||
|
local venv_parent
|
||||||
|
venv_parent="$(dirname "$VIRTUAL_ENV")" # .../.venv
|
||||||
|
venv_parent="$(dirname "$venv_parent")" # project root
|
||||||
|
case "$PWD/" in
|
||||||
|
"$venv_parent"/*) ;; # still inside the project
|
||||||
|
*)
|
||||||
|
deactivate 2>/dev/null || true
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If no venv active (or we just deactivated), and this directory has a .venv, activate it.
|
||||||
|
if [[ -z "${VIRTUAL_ENV:-}" && -f "$venv_path/bin/activate" ]]; then
|
||||||
|
# shellcheck disable=SC1090
|
||||||
|
source "$venv_path/bin/activate"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Wrap cd so it triggers venv auto-activation.
|
||||||
|
cd() {
|
||||||
|
builtin cd "$@" || return
|
||||||
|
_venv_auto_activate
|
||||||
|
}
|
||||||
|
|
||||||
|
# Also run once for the starting directory when the shell launches.
|
||||||
|
_venv_auto_activate
|
||||||
|
|||||||
Reference in New Issue
Block a user