diff --git a/.bashrc b/.bashrc index 5e146b0..0b53fc9 100644 --- a/.bashrc +++ b/.bashrc @@ -12,7 +12,7 @@ fi if [ -f /etc/os-release ]; then distro=$(awk -F= '/^NAME/{print $ssss2}' /etc/os-release | tr -d '"') if [[ "$distro" == *"Pop!_OS"* ]]; then - export CGO_CFLAGS="-I/usr/include" + export CGO_CFLAGS="-I/usr/include" fi fi @@ -22,6 +22,11 @@ if [[ "$(uname -a)" == *"microsoft-standard-WSL2"* ]]; then alias winget='winget.exe' fi +# Set SSH_AUTH_SOCK to ~/.1password/agent.sock, but only if we don't already have a SSH_AUTH_SOCK +if [ -z "$SSH_AUTH_SOCK" ]; then + export SSH_AUTH_SOCK=~/.1password/agent.sock +fi + # Docker Compose Alias (Mostly for old shell scripts) alias docker-compose='docker compose' @@ -77,7 +82,7 @@ inuse() { local CYAN='\033[0;36m' local BOLD='\033[1m' local NC='\033[0m' # No Color - + # Input validation if [ $# -eq 0 ]; then echo -e "${RED}Usage:${NC} inuse " @@ -87,7 +92,7 @@ inuse() { echo -e "${YELLOW} inuse --list${NC}" return 1 fi - + # Handle --help option if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then echo -e "${CYAN}${BOLD}inuse - Check if a port is in use${NC}" @@ -114,24 +119,24 @@ inuse() { echo return 0 fi - + # Handle --list option if [ "$1" = "--list" ] || [ "$1" = "-l" ]; then if ! command -v docker >/dev/null 2>&1; then echo -e "${RED}Error:${NC} Docker is not available" return 1 fi - + echo -e "${CYAN}${BOLD}Docker Services with Listening Ports:${NC}" echo - + # Get all running containers local containers=$(docker ps --format "{{.Names}}" 2>/dev/null) if [ -z "$containers" ]; then echo -e "${YELLOW}No running Docker containers found${NC}" return 0 fi - + local found_services=false while IFS= read -r container; do # Get port mappings for this container @@ -140,9 +145,9 @@ inuse() { # Get container image name (clean it up) local image=$(docker inspect "$container" 2>/dev/null | grep -o '"Image": *"[^"]*"' | cut -d'"' -f4 | head -1) local clean_image=$(echo "$image" | sed 's/sha256:[a-f0-9]*/[image-hash]/' | sed 's/^.*\///') - + echo -e "${GREEN}📦 ${BOLD}$container${NC} ${CYAN}($clean_image)${NC}" - + # Parse and display ports nicely echo "$ports" | while IFS= read -r port_line; do if [[ "$port_line" =~ ([0-9]+)/(tcp|udp).*0\.0\.0\.0:([0-9]+) ]]; then @@ -161,7 +166,7 @@ inuse() { found_services=true fi done <<< "$containers" - + # Also check for host networking containers local host_containers=$(docker ps --format "{{.Names}}" --filter "network=host" 2>/dev/null) if [ -n "$host_containers" ]; then @@ -174,22 +179,22 @@ inuse() { echo found_services=true fi - + if [ "$found_services" = false ]; then echo -e "${YELLOW}No Docker services with exposed ports found${NC}" fi - + return 0 fi - + local port="$1" - + # Validate port number if ! [[ "$port" =~ ^[0-9]+$ ]] || [ "$port" -lt 1 ] || [ "$port" -gt 65535 ]; then echo -e "${RED}Error:${NC} Invalid port number. Must be between 1 and 65535." return 1 fi - + # Check if port is in use first local port_in_use=false if command -v ss >/dev/null 2>&1; then @@ -201,15 +206,15 @@ inuse() { port_in_use=true fi fi - + if [ "$port_in_use" = false ]; then echo -e "${RED}✗ Port $port is FREE${NC}" return 1 fi - + # Port is in use, now find what's using it local found_process=false - + # Method 1: Try netstat first (most reliable for PID info) if command -v netstat >/dev/null 2>&1; then local netstat_result=$(netstat -tulpn 2>/dev/null | grep ":$port ") @@ -218,7 +223,7 @@ inuse() { local pid=$(echo "$line" | awk '{print $7}' | cut -d'/' -f1) local process_name=$(echo "$line" | awk '{print $7}' | cut -d'/' -f2) local protocol=$(echo "$line" | awk '{print $1}') - + if [[ "$pid" =~ ^[0-9]+$ ]] && [ -n "$process_name" ]; then # Check if it's a Docker container local docker_info="" @@ -246,14 +251,14 @@ inuse() { fi fi fi - + echo -e "${GREEN}✓ Port $port ($protocol) in use by ${BOLD}$process_name${NC} ${GREEN}as PID ${BOLD}$pid${NC}$docker_info" found_process=true fi done <<< "$netstat_result" fi fi - + # Method 2: Try ss if netstat didn't work if [ "$found_process" = false ] && command -v ss >/dev/null 2>&1; then local ss_result=$(ss -tulpn 2>/dev/null | grep ":$port ") @@ -261,7 +266,7 @@ inuse() { while IFS= read -r line; do local pid=$(echo "$line" | grep -o 'pid=[0-9]*' | cut -d'=' -f2) local protocol=$(echo "$line" | awk '{print $1}') - + if [[ "$pid" =~ ^[0-9]+$ ]]; then local process_name=$(ps -p "$pid" -o comm= 2>/dev/null) if [ -n "$process_name" ]; then @@ -287,7 +292,7 @@ inuse() { fi fi fi - + echo -e "${GREEN}✓ Port $port ($protocol) in use by ${BOLD}$process_name${NC} ${GREEN}as PID ${BOLD}$pid${NC}$docker_info" found_process=true fi @@ -295,7 +300,7 @@ inuse() { done <<< "$ss_result" fi fi - + # Method 3: Try fuser as last resort if [ "$found_process" = false ] && command -v fuser >/dev/null 2>&1; then local fuser_pids=$(fuser "$port/tcp" 2>/dev/null) @@ -312,7 +317,7 @@ inuse() { done fi fi - + # Method 4: Check for Docker containers more accurately if [ "$found_process" = false ] && command -v docker >/dev/null 2>&1; then # First, try to find containers with published ports matching our port @@ -343,13 +348,13 @@ inuse() { fi fi fi - + # If we still haven't found the process, show a generic message if [ "$found_process" = false ]; then echo -e "${YELLOW}⚠ Port $port is in use but unable to identify the process${NC}" echo -e "${CYAN} This might be due to insufficient permissions or the process being in a different namespace${NC}" fi - + return 0 } diff --git a/config/ssh/config b/config/ssh/config index 71b5907..ebbf56b 100644 --- a/config/ssh/config +++ b/config/ssh/config @@ -1,5 +1,4 @@ Host * - IdentityAgent ~/.1password/agent.sock AddKeysToAgent yes ForwardAgent yes