Compare commits

...

5 Commits

11 changed files with 268 additions and 65 deletions

12
.bashrc
View File

@@ -75,6 +75,7 @@ esac
## Begin .rc.d stuff ## Begin .rc.d stuff
PATH="/home/tom/Android/android-studio/bin:$PATH"
## Source all scripts in ~/.rc.d ## Source all scripts in ~/.rc.d
for f in ~/.rc.d/*.sh; do for f in ~/.rc.d/*.sh; do
source "$f" source "$f"
@@ -108,3 +109,14 @@ fi
# PATH="$HOME/.local/bin:$PATH" # PATH="$HOME/.local/bin:$PATH"
# fi # fi
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
# Load Angular CLI autocompletion.
source <(ng completion script)
# Initialize profile environment
[ -f "$HOME/.init_profile" ] && . "$HOME/.init_profile"

View File

@@ -7,10 +7,13 @@
st = status st = status
cm = commit -m cm = commit -m
aa = add --all . aa = add --all .
show-origin-url = remote get-url origin
cam = !git add --all . && git commit --amend --no-edit cam = !git add --all . && git commit --amend --no-edit
rbs = !git checkout main && git pull && git checkout - && git rebase main rbs = !git checkout main && git pull && git checkout - && git rebase main
cop = "!f() { git checkout ${1-main}; git pull; }; f" cop = "!f() { git checkout ${1-main}; git pull; }; f"
lazy = commit -C HEAD@{1} lazy = commit -C HEAD@{1}
cp = cherry-pick
anne = commit --amend --no-edit
[init] [init]
defaultBranch = main defaultBranch = main
[pull] [pull]
@@ -22,3 +25,8 @@
lowSpeedLimit = 1000 lowSpeedLimit = 1000
lowSpeedTime = 60 lowSpeedTime = 60
postBuffer = 524288000 postBuffer = 524288000
[filter "lfs"]
clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f
process = git-lfs filter-process
required = true

1
.gitignore vendored
View File

@@ -1 +1,2 @@
/history /history
/.vscode/extensions

44
.init_profile Normal file
View File

@@ -0,0 +1,44 @@
#!/usr/bin/env sh
## Source all scripts in ~/.rc.d
if [ -d "$HOME/.rc.d" ]; then
for f in "$HOME/.rc.d"/*.sh; do
if [ -r "$f" ]; then
. "$f"
fi
done
# Source shell-specific scripts if any
if [ -n "$BASH_VERSION" ]; then
for f in "$HOME/.rc.d"/*.bash; do
if [ -r "$f" ]; then
. "$f"
fi
done
elif [ -n "$ZSH_VERSION" ]; then
for f in "$HOME/.rc.d"/*.zsh; do
if [ -r "$f" ]; then
. "$f"
fi
done
fi
fi
## Autocompletion (Bash)
if [ -n "$BASH_VERSION" ]; then
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
fi
## Paths
# Prepend common personal bin directories to path
if [ -d "$HOME/bin" ] ; then PATH="$HOME/bin:$PATH"; fi
if [ -d "$HOME/.bin" ] ; then PATH="$HOME/.bin:$PATH"; fi
if [ -d "$HOME/.local/bin" ] ; then PATH="$HOME/.local/bin:$PATH"; fi
if [ -d "$HOME/Applications/bin" ] ; then PATH="$HOME/Applications/bin:$PATH"; fi
export PATH

View File

@@ -6,49 +6,67 @@ ensure_alias() {
fi fi
} }
# Detect WSL is_macos() { [ "$(uname)" = "Darwin" ]; }
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. is_linux() { [ "$(uname)" = "Linux" ]; }
# File Manipulation
# TODO: bash ls doesn't need -G or maybe macs don't. Figure that out and use that test here. is_wsl() {
alias ls='ls -G --color=auto' # Detect WSL1/WSL2/WSLg kernels
alias lsd='ls -G --color=auto -d' case "$(uname -r)" in
alias ll='ls -G --color=auto -l' *Microsoft*|*microsoft*|*WSL2*|*WSLg*) return 0 ;;
alias lld='ls -G --color=auto -l -d' esac
alias lsg='ls | grep --color' return 1
alias llg='ls -l| grep --color' }
#alias ln='ln -ivw'
alias ln='ln -iv' if is_macos; then alias ls='ls -G'
elif is_linux; then alias ls='ls --color=auto'; fi
alias lsd='ls -d'
alias ll='ls -l'
alias lld='ls -l -d'
alias lsg='ls | grep'
alias llg='ls -l | grep'
if is_macos; then alias ln='ln -ivw'
elif is_linux; alias ln='ln -iv'; fi
if is_linux; then
alias grep='grep --color=auto' alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto' alias fgrep='grep --color=auto -F'
alias egrep='egrep --color=auto' alias egrep='grep --color=auto -E'
else
alias fgrep='grep -F'
alias egrep='grep -E'
fi
alias slash='ls -SlAhr' alias slash='ls -SlAhr'
alias slasher='ls -SlAh' alias slasher='ls -SlAh'
alias slashed='ls -SlAhrd' alias slashed='ls -SlAhrd'
alias ds='function f() { du -h -d 1 $* | sort -h | tee ~/dirsize ; unset -f f; }; f' ds() {
alias dud='function { du -h -d 1 $* | sort -h }' du -h -d 1 "$@" | sort -h | tee "$HOME/dirsize"
alias dud='function f() { du -h -d 1 "$@" 2>/dev/null | sort -h ; unset -f f; }; f' }
alias dudr='function { du -h -d 1 $* | sort -h -r }' dud() {
alias dudr='function f() { du -h -d 1 "$@" 2>/dev/null | sort -h -r ; unset -f f; }; f' du -h -d 1 "$@" 2>/dev/null | sort -h
}
dudr() {
du -h -d 1 "$@" 2>/dev/null | sort -h -r
}
alias mvn='mv -n' alias mvn='mv -n'
alias gmv='mv $* ~/Google\ Drive/My\ Drive/' gmv() { mv "$@" "$HOME/Google Drive/My Drive/"; }
alias gmvn='mv -n $* ~/Google\ Drive/My\ Drive/' gmvn() { mv -n "$@" "$HOME/Google Drive/My Drive/"; }
alias omv='mv $* ~/OneDrive/' omv() { mv "$@" "$HOME/OneDrive/"; }
alias omvn='mv -n $* ~/OneDrive/' omvn() { mv -n "$@" "$HOME/OneDrive/"; }
alias mv='mv -i' alias mv='mv -i'
alias rm='rm -i' alias rm='rm -i'
alias rs='rsync -avhz --progress' alias rs='rsync -avhz --progress'
alias rsfat='rs --no-perms --no-owner --no-group --no-times' alias rsfat='rsync -avhz --progress --no-perms --no-owner --no-group --no-times'
rscheck() {
rsync -avhzc --itemize-changes --dry-run "$@" |
grep "^>f[^+].*[sc]"
}
alias md=mkdir alias md=mkdir
alias rd=rmdir alias rd=rmdir
# Git shortcuts # Git shortcuts
alias it=git alias it=git
alias rsgit='rsync -avhz --no-perms --exclude='\''.git'\'' --exclude='\''.vscode'\' alias rsgit="rsync -avhz --no-perms --exclude='.git' --exclude='.vscode'"
# Bazel shortcuts # Bazel shortcuts
alias refresh_bazel='bazel run @hedron_compile_commands//:refresh_all' alias refresh_bazel='bazel run @hedron_compile_commands//:refresh_all'
@@ -62,16 +80,30 @@ alias cbq='clear && bazel query //...'
# Utilities # Utilities
alias iwyu='include-what-you-use' alias iwyu='include-what-you-use'
alias show-android-emulators="ps aux | head -n 1 && ps aux | grep avd | sed '$d'" show_android_emulators() {
alias kill-all-android-emulators='adb devices | grep emulator | cut -f1 | while read line; do adb -s $line emu kill; done' ps aux | head -n 1
ps aux | grep avd | sed '$d'
}
kill_all_android_emulators() {
adb devices |
awk '/emulator/{print $1}' |
while read -r dev; do adb -s "$dev" emu kill; done
}
alias freespace="df -I -h -T nodevfs | grep -i -v -E '/\.timemachine/|/System/Volumes/|/com\.apple\.TimeMachine\.localsnapshots/' | sed -e 's/ / /g'" alias freespace="df -I -h -T nodevfs | grep -i -v -E '/\.timemachine/|/System/Volumes/|/com\.apple\.TimeMachine\.localsnapshots/' | sed -e 's/ / /g'"
alias fs="df -I -h -T nodevfs | grep -i -v -E '/\.timemachine/|/System/Volumes/|/com\.apple\.TimeMachine\.localsnapshots/' | sed -e 's/ / /g'" alias fs="df -I -h -T nodevfs | grep -i -v -E '/\.timemachine/|/System/Volumes/|/com\.apple\.TimeMachine\.localsnapshots/' | sed -e 's/ / /g'"
alias hashes='md5deep -r' alias hashes='md5deep -r'
# Mac equivalent of lsusb on linux # Mac equivalent of lsusb on linux
alias lsusb='system_profiler SPUSBDataType' if is_macos; then alias lsusb='system_profiler SPUSBDataType'; fi
alias tea='tee -a' alias tea='tee -a'
alias find_recent='function { find . $* -exec ls -ltr {} + }' find_recent() {
alias find_recent='function f() { find . $* -exec ls -ltr {} + ; unset -f f; }; f' find . "$@" -exec ls -ltr "{}" +
}
mount_nas() {
mkdir -p "$HOME/nas/home"
remote_home=$(ssh deepthought "printf %s \"\$HOME\"")
sshfs "deepthought:$remote_home" "$HOME/nas/home"
}
# pbcopy # pbcopy
if ! command -v pbcopy >/dev/null 2>&1; then if ! command -v pbcopy >/dev/null 2>&1; then
@@ -79,7 +111,9 @@ if ! command -v pbcopy >/dev/null 2>&1; then
ensure_alias pbcopy 'wl-copy' ensure_alias pbcopy 'wl-copy'
elif command -v xclip >/dev/null 2>&1; then elif command -v xclip >/dev/null 2>&1; then
ensure_alias pbcopy 'xclip -selection clipboard' ensure_alias pbcopy 'xclip -selection clipboard'
elif [ "$is_wsl" = true ] && command -v clip.exe >/dev/null 2>&1; then elif command -v xsel >/dev/null 2>&1; then
ensure_alias pbcopy 'xsel --clipboard --input'
elif is_wsl && command -v clip.exe >/dev/null 2>&1; then
ensure_alias pbcopy 'clip.exe' ensure_alias pbcopy 'clip.exe'
fi fi
fi fi
@@ -90,42 +124,88 @@ if ! command -v pbpaste >/dev/null 2>&1; then
ensure_alias pbpaste 'wl-paste' ensure_alias pbpaste 'wl-paste'
elif command -v xclip >/dev/null 2>&1; then elif command -v xclip >/dev/null 2>&1; then
ensure_alias pbpaste 'xclip -selection clipboard -o' ensure_alias pbpaste 'xclip -selection clipboard -o'
elif [ "$is_wsl" = true ] && command -v powershell.exe >/dev/null 2>&1; then elif command -v xsel >/dev/null 2>&1; then
ensure_alias pbpaste 'xsel --clipboard --output'
elif is_wsl && command -v powershell.exe >/dev/null 2>&1; then
ensure_alias pbpaste 'powershell.exe -noprofile Get-Clipboard' ensure_alias pbpaste 'powershell.exe -noprofile Get-Clipboard'
fi fi
fi fi
log_and_do() {
printf '# %s\n' "$1" >> "$2"
bash -c "$1"
}
# In Development # In Development
# Dosn't work if command is piped e.g. `log_and_do "ls | tee out.txt" my_other_file.txt`
# or stdout is redirected e.g. `log_and_do "ls > out.txt" my_other_file.txt`
alias log_and_do='function { `echo "# $1 >> $2\n" > $2 && echo $1` >> $2 }'
# This should get the PIDs of any avd commands running and kill-9 them and then do the
# same as kill-all-android-emulators to clean them up after.
# alias kaae="kill -9 `ps aux | grep avd | sed '$d' | cut -f 2 -w` > /dev/null"
# TODO: Stuff I don't know why other configs setup
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
#alias ll='ls -alF'
#alias la='ls -A'
#alias l='ls -CF'
# From Bash on Ubuntu # From Bash on Ubuntu
# Add an "alert" alias for long running commands. Use like so: # Add an "alert" alias for long running commands. Use like so:
# sleep 10; alert # sleep 10; alert
#alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"' #alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
alert() {
local last_cmd exit_status
exit_status=$?
# Get last command text
if [[ -n "$ZSH_VERSION" ]]; then
last_cmd=$(fc -ln -1)
else
last_cmd=$(history | tail -n1 | sed 's/^[ ]*[0-9]\+[ ]*//')
fi
# macOS notification
if is_macos; then
terminal-notifier -message "$last_cmd" \
-title "Command finished (exit $exit_status)"
return
fi
# Linux notification
if command -v notify-send >/dev/null 2>&1; then
notify-send "Command finished (exit $exit_status)" "$last_cmd"
fi
}
# WSL Specific
#alias pbcopy=clip.exe
#alias pbpaste="powershell.exe -noprofile Get-Clipboard"
# SSH-Agent setup # SSH-Agent setup
# alias sshgo='eval $(ssh-agent -s) && ssh-add ~/.ssh/id_ed25519 ~/.ssh/id_rsa ~/.ssh/id_win_ed25519 ~/.ssh/id_win_rsa' sshgo() {
alias sshgo='eval $(ssh-agent -s) && for key in ~/.ssh/id_*; do [[ -f "$key" && "${key##*/}" != *.* ]] && ssh-add "$key"; done' # Start agent only if this shell doesn't already have one
if [[ -n "$SSH_AUTH_SOCK" && -n "$SSH_AGENT_PID" ]] &&
ps -p "$SSH_AGENT_PID" >/dev/null 2>&1; then
echo "ssh-agent already running for this session."
else
eval "$(ssh-agent -s)"
fi
# Load keys only if not already loaded
for key in "$HOME"/.ssh/id_*; do
[[ -f "$key" ]] || continue
[[ "$key" == *.pub ]] && continue
fingerprint=$(ssh-keygen -lf "$key" | awk '{print $2}')
if ssh-add -l 2>/dev/null | grep -q "$fingerprint"; then
continue
fi
ssh-add "$key"
done
}
install_local_bin() {
sudo install -m 755 -o root -g root "$1" /usr/local/bin
}
install_user_bin() {
mkdir -p "$HOME/bin"
cp "$1" "$HOME/bin/"
}
alias build_and_test='cmake -S . -B build && cmake --build build -- -j$(nproc) && ctest --test-dir build --output-on-failure'
alias inspect-video='mediainfo --Inform="Video;Codec: %Format%\nProfile: %Format_Profile%\nResolution: %Width%x%Height%\nBitrate: %BitRate/String%\nBitrate mode: %BitRate_Mode%\nFrame rate: %FrameRate% fps\n"' alias inspect-video='mediainfo --Inform="Video;Codec: %Format%\nProfile: %Format_Profile%\nResolution: %Width%x%Height%\nBitrate: %BitRate/String%\nBitrate mode: %BitRate_Mode%\nFrame rate: %FrameRate% fps\n"'
alias wget-rip='wget --page-requisites --convert-links --adjust-extension --no-clobber --span-hosts' alias wget-rip='wget --page-requisites --convert-links --adjust-extension --no-clobber --span-hosts'
alias wget-rip='wget --page-requisites --convert-links --adjust-extension --no-clobber --span-hosts -r -l1' alias wget-rip='wget --page-requisites --convert-links --adjust-extension --no-clobber --span-hosts -r -l1'
alias wget-rip-lite='wget --page-requisites --convert-links --adjust-extension --no-clobber --span-hosts -r -l1 -A jpg,jpeg,png,gif,html,css,ttf,otf' alias wget-rip-lite='wget --page-requisites --convert-links --adjust-extension --no-clobber --span-hosts -r -l1 -A jpg,jpeg,png,gif,html,css,ttf,otf'
alias mount-nas='mkdir -p ~/nas/tom && sshfs deepthought:/mnt/Data/Private/Homes/tom ~/nas/tom'
alias installlocalbin='function f() { sudo install -m 755 -o root -g root "$1" /usr/local/bin ; unset -f f; } f'
alias installuserbin='function f() { mkdir -p ~/bin ; cp "$1" ~/bin/ ; unset -f f; } f'

View File

@@ -1,6 +1,6 @@
# The next line updates PATH for the Google Cloud SDK. # The next line updates PATH for the Google Cloud SDK.
if [ -f '/home/tom/Downloads/GCloud/google-cloud-sdk/path.bash.inc' ]; then . '/home/tom/Downloads/GCloud/google-cloud-sdk/path.bash.inc'; fi if [ -f "$HOME/google-cloud-sdk/path.bash.inc" ]; then source "$HOME/google-cloud-sdk/path.bash.inc"; fi
# The next line enables shell command completion for gcloud. # The next line enables shell command completion for gcloud.
if [ -f '/home/tom/Downloads/GCloud/google-cloud-sdk/completion.bash.inc' ]; then . '/home/tom/Downloads/GCloud/google-cloud-sdk/completion.bash.inc'; fi if [ -f "$HOME/google-cloud-sdk/completion.bash.inc" ]; then source "$HOME/google-cloud-sdk/completion.bash.inc"; fi

5
.yarnrc Normal file
View File

@@ -0,0 +1,5 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
lastUpdateCheck 1768790207834

3
.zshrc
View File

@@ -46,3 +46,6 @@ SAVEHIST=10000
# zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31' # zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
# zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd' # zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'
# Initialize profile environment
[ -f "$HOME/.init_profile" ] && . "$HOME/.init_profile"

13
import.sh Executable file
View File

@@ -0,0 +1,13 @@
#!/usr/bin/env bash
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/install_files"
cd "$SCRIPT_DIR" || exit 1
for file in "${IMPORT_FILES[@]}"; do
if [ -e "$HOME/$file" ] || [ -L "$HOME/$file" ]; then
cp -r "$HOME/$file" ./
fi
done

View File

@@ -1,7 +1,24 @@
#! /usr/bin/env sh #!/usr/bin/env bash
cp .gitconfig .gitignore .gitignore_global ../
cp .hgignore_global ../ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cp .profile ../ source "$SCRIPT_DIR/install_files"
cp .bash_logout .bashrc ../
cp -r .zsh_functions .zprofile .zshenv .zshrc ../ cd "$SCRIPT_DIR" || exit 1
cp -r .rc.d ../
# Copy files and directories
for file in "${INSTALL_FILES[@]}"; do
if [ -e "./$file" ] || [ -L "./$file" ]; then
cp -r "./$file" "$HOME/"
fi
done
# Ensure ~/.bashrc and ~/.zshrc exist and source ~/.init_profile
SOURCE_LINE='[ -f "$HOME/.init_profile" ] && . "$HOME/.init_profile"'
for rc in "$HOME/.bashrc" "$HOME/.zshrc"; do
touch "$rc"
if ! grep -qF "$SOURCE_LINE" "$rc"; then
printf "\n# Initialize profile environment\n%s\n" "$SOURCE_LINE" >> "$rc"
fi
done

20
install_files Normal file
View File

@@ -0,0 +1,20 @@
INSTALL_FILES=(
".gitconfig"
".gitignore"
".gitignore_global"
".hgignore_global"
".init_profile"
".rc.d"
".yarnrc"
".zsh_functions"
)
IMPORT_FILES=(
"${INSTALL_FILES[@]}"
".bash_logout"
".bashrc"
".profile"
".zprofile"
".zshenv"
".zshrc"
)