From cbfe4980097a995c8cf9984dcafdfead8fc1e998 Mon Sep 17 00:00:00 2001 From: Tom Hicks Date: Fri, 14 Nov 2025 15:22:48 -0800 Subject: [PATCH] Adds better pbcopy and pbpaste aliases. Reorganizes .gitconfig. --- .bashrc | 5 +++-- .gitconfig | 13 +++++-------- .rc.d/aliases.sh | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/.bashrc b/.bashrc index 2da2781..053b63b 100644 --- a/.bashrc +++ b/.bashrc @@ -2,7 +2,7 @@ # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) # for examples -## If not running interactively, don't do anything +# If not running interactively, don't do anything case $- in *i*) ;; *) return;; @@ -77,8 +77,9 @@ esac ## Source all scripts in ~/.rc.d for f in ~/.rc.d/*.sh; do - source "$f" + source "$f" done +# TODO: do the same for ~/.rc.d/*.bash to only do bash scripts or make the scripts figure out what shell they are under. ## Autocompletion diff --git a/.gitconfig b/.gitconfig index cbce707..8bf8e07 100644 --- a/.gitconfig +++ b/.gitconfig @@ -1,10 +1,4 @@ -[user] - name = Tom Hicks - email = headunter3@gmail.com -[core] - excludesfile = /Users/tom/.gitignore_global [alias] - amend = commit --amend --no-edit br = branch brr = branch -r co = checkout @@ -16,7 +10,10 @@ rbs = !git checkout main && git pull && git checkout - && git rebase main cop = "!f() { git checkout ${1-main}; git pull; }; f" lazy = commit -C HEAD@{1} -[pull] - ff = only [init] defaultBranch = main +[pull] + ff = only +[user] + name = Tom Hicks + email = headhunter3@gmail.com diff --git a/.rc.d/aliases.sh b/.rc.d/aliases.sh index da6ba3c..8bb1c0f 100755 --- a/.rc.d/aliases.sh +++ b/.rc.d/aliases.sh @@ -1,3 +1,17 @@ +# Helper: define alias only if command doesn't already exist +ensure_alias() { + local name="$1" cmd="$2" + if ! command -v "$name" >/dev/null 2>&1; then + alias "$name"="$cmd" + fi +} + +# Detect WSL +is_wsl=false +if grep -qi microsoft /proc/version 2>/dev/null; then + is_wsl=true +fi + # TODO: detect color support and enable/disable color in aliases based on that. # File Manipulation # TODO: bash ls doesn't need -G or maybe macs don't. Figure that out and use that test here. @@ -58,6 +72,29 @@ alias tea='tee -a' alias find_recent='function { find . $* -exec ls -ltr {} + }' alias find_recent='function f() { find . $* -exec ls -ltr {} + ; unset -f f; }; f' +# pbcopy +if ! command -v pbcopy >/dev/null 2>&1; then + if command -v wl-copy >/dev/null 2>&1; then + ensure_alias pbcopy 'wl-copy' + elif command -v xclip >/dev/null 2>&1; then + ensure_alias pbcopy 'xclip -selection clipboard' + elif [ "$is_wsl" = true ] && command -v clip.exe >/dev/null 2>&1; then + ensure_alias pbcopy 'clip.exe' + fi +fi + +# pbpaste +if ! command -v pbpaste >/dev/null 2>&1; then + if command -v wl-paste >/dev/null 2>&1; then + ensure_alias pbpaste 'wl-paste' + elif command -v xclip >/dev/null 2>&1; then + ensure_alias pbpaste 'xclip -selection clipboard -o' + elif [ "$is_wsl" = true ] && command -v powershell.exe >/dev/null 2>&1; then + ensure_alias pbpaste 'powershell.exe -noprofile Get-Clipboard' + fi +fi + + # In Development # Dosn't work if command is piped e.g. `log_and_do "ls | tee out.txt" my_other_file.txt`