From db2c02bd2d3731a5936a39230eb378a0db19d14c Mon Sep 17 00:00:00 2001 From: David Tomaschik Date: Tue, 21 Apr 2026 15:59:38 -0700 Subject: [PATCH] Cleanup --- bin/disk-benchmark | 11 +++++- bin/google-chrome-burp | 6 ++- bin/{ => linux}/autostart.py | 0 bin/{ => linux}/backup.sh | 0 bin/{ => linux}/checksec.sh | 0 bin/{ => linux}/i3lock.sh | 0 bin/{ => linux}/nvidia_hold.sh | 0 bin/{ => linux}/pactl_helper | 0 bin/{ => linux}/qdisc_span.sh | 0 bin/{ => linux}/remove-wine-associations | 0 bin/{ => linux}/setup/apt_proxy.sh | 0 bin/{ => linux}/setup/i3.sh | 0 bin/{ => linux}/setup/spicerandr.sh | 0 bin/{ => linux}/smart-copy-paste | 0 bin/{ => linux}/switch_virt.sh | 0 bin/screenshot.sh | 25 ++++++++++++ dotfiles/aliases | 48 ++++++++++++++---------- dotfiles/config/fish/conf.d/aliases.fish | 48 ++++++++++++++---------- dotfiles/config/fish/config.fish | 2 + dotfiles/shenv | 2 + dotfiles/tmux.conf | 7 ++-- dotfiles/zshrc | 2 + dotfiles/zshrc.d/alert.zsh | 11 +++++- dotfiles/zshrc.d/android.zsh | 11 ++++-- dotfiles/zshrc.d/assemble.zsh | 6 ++- dotfiles/zshrc.d/functions.zsh | 8 +++- dotfiles/zshrc.d/lesshighlight.zsh | 18 +++++++-- 27 files changed, 150 insertions(+), 55 deletions(-) rename bin/{ => linux}/autostart.py (100%) rename bin/{ => linux}/backup.sh (100%) rename bin/{ => linux}/checksec.sh (100%) rename bin/{ => linux}/i3lock.sh (100%) rename bin/{ => linux}/nvidia_hold.sh (100%) rename bin/{ => linux}/pactl_helper (100%) rename bin/{ => linux}/qdisc_span.sh (100%) rename bin/{ => linux}/remove-wine-associations (100%) rename bin/{ => linux}/setup/apt_proxy.sh (100%) rename bin/{ => linux}/setup/i3.sh (100%) rename bin/{ => linux}/setup/spicerandr.sh (100%) rename bin/{ => linux}/smart-copy-paste (100%) rename bin/{ => linux}/switch_virt.sh (100%) diff --git a/bin/disk-benchmark b/bin/disk-benchmark index ad46705..45d6ef9 100755 --- a/bin/disk-benchmark +++ b/bin/disk-benchmark @@ -12,8 +12,17 @@ fi trap "test -f ${FILENAME} && rm -f ${FILENAME}" EXIT +IOENGINE="libaio" +DIRECT=1 +if [ "$(uname)" = "Darwin" ]; then + IOENGINE="posixaio" + # macOS doesn't support O_DIRECT in the same way, but fio's direct=1 + # handles it via F_NOCACHE if supported. + DIRECT=1 +fi + fio --loops=5 --size=${BENCHMARK_SIZE} --filename=${FILENAME} \ - --stonewall --ioengine=libaio --direct=1 \ + --stonewall --ioengine=${IOENGINE} --direct=${DIRECT} \ --name=Seqread --bs=1m --rw=read \ --name=Seqwrite --bs=1m --rw=write \ --name=512Kread --bs=512k --rw=randread \ diff --git a/bin/google-chrome-burp b/bin/google-chrome-burp index 0aab1fd..d3d617d 100755 --- a/bin/google-chrome-burp +++ b/bin/google-chrome-burp @@ -1,6 +1,10 @@ #!/bin/bash CHROME_BINS="google-chrome-beta google-chrome" +if [ "$(uname)" = "Darwin" ]; then + CHROME_BINS="${CHROME_BINS} /Applications/Google\ Chrome\ Beta.app/Contents/MacOS/Google\ Chrome\ Beta /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome" +fi + for bin in ${CHROME_BINS} ; do if command -v ${bin} >/dev/null 2>&1 ; then CHROME=$(command -v ${bin}) @@ -18,4 +22,4 @@ export HOME=${HOME}/.chrome-pentest mkdir -p ${HOME} # Launch chrome for burp -exec ${CHROME} --user-data-dir=${HOME}/chrome-pentest --proxy-server=127.0.0.1:8080 +exec "${CHROME}" --user-data-dir=${HOME}/chrome-pentest --proxy-server=127.0.0.1:8080 diff --git a/bin/autostart.py b/bin/linux/autostart.py similarity index 100% rename from bin/autostart.py rename to bin/linux/autostart.py diff --git a/bin/backup.sh b/bin/linux/backup.sh similarity index 100% rename from bin/backup.sh rename to bin/linux/backup.sh diff --git a/bin/checksec.sh b/bin/linux/checksec.sh similarity index 100% rename from bin/checksec.sh rename to bin/linux/checksec.sh diff --git a/bin/i3lock.sh b/bin/linux/i3lock.sh similarity index 100% rename from bin/i3lock.sh rename to bin/linux/i3lock.sh diff --git a/bin/nvidia_hold.sh b/bin/linux/nvidia_hold.sh similarity index 100% rename from bin/nvidia_hold.sh rename to bin/linux/nvidia_hold.sh diff --git a/bin/pactl_helper b/bin/linux/pactl_helper similarity index 100% rename from bin/pactl_helper rename to bin/linux/pactl_helper diff --git a/bin/qdisc_span.sh b/bin/linux/qdisc_span.sh similarity index 100% rename from bin/qdisc_span.sh rename to bin/linux/qdisc_span.sh diff --git a/bin/remove-wine-associations b/bin/linux/remove-wine-associations similarity index 100% rename from bin/remove-wine-associations rename to bin/linux/remove-wine-associations diff --git a/bin/setup/apt_proxy.sh b/bin/linux/setup/apt_proxy.sh similarity index 100% rename from bin/setup/apt_proxy.sh rename to bin/linux/setup/apt_proxy.sh diff --git a/bin/setup/i3.sh b/bin/linux/setup/i3.sh similarity index 100% rename from bin/setup/i3.sh rename to bin/linux/setup/i3.sh diff --git a/bin/setup/spicerandr.sh b/bin/linux/setup/spicerandr.sh similarity index 100% rename from bin/setup/spicerandr.sh rename to bin/linux/setup/spicerandr.sh diff --git a/bin/smart-copy-paste b/bin/linux/smart-copy-paste similarity index 100% rename from bin/smart-copy-paste rename to bin/linux/smart-copy-paste diff --git a/bin/switch_virt.sh b/bin/linux/switch_virt.sh similarity index 100% rename from bin/switch_virt.sh rename to bin/linux/switch_virt.sh diff --git a/bin/screenshot.sh b/bin/screenshot.sh index 1c4df8c..fe87177 100755 --- a/bin/screenshot.sh +++ b/bin/screenshot.sh @@ -5,8 +5,14 @@ set -ue TOOLS="flameshot scrot" +if [ "$(uname)" = "Darwin" ]; then + TOOLS="screencapture ${TOOLS}" +fi + SCREENDIR=${SCREENDIR:-${HOME}/Pictures/Screenshots} SCROT_FORMAT="%F-%T.png" +# Filename for screencapture +FILE_NAME=$(date "+%Y-%m-%d-%H%M%S.png") function default_screenshot_command { for tool in ${TOOLS} ; do @@ -41,10 +47,29 @@ function scrot_full_capture { scrot "${SCREENDIR}/${SCROT_FORMAT}" } +function mac_capture { + local mode="${1}" + local target="${SCREENDIR}/${FILE_NAME}" + case "${mode}" in + region) + screencapture -i "${target}" + ;; + window) + screencapture -i -w "${target}" + ;; + full) + screencapture "${target}" + ;; + esac +} + case "${CMD}" in region|window|full) mkdir -p "${SCREENDIR}" case "${TOOL}" in + screencapture) + mac_capture "${CMD}" + ;; flameshot) case "${CMD}" in region|window) diff --git a/dotfiles/aliases b/dotfiles/aliases index 91104f5..ee4febb 100755 --- a/dotfiles/aliases +++ b/dotfiles/aliases @@ -1,9 +1,6 @@ # General aliases, should only be sourced in interactive shells # Try to keep in sync with ~/.config/fish/conf.d/aliases.fish -# Cryptsetup alias -alias luksFormat='cryptsetup luksFormat --type=luks2 --pbkdf-memory=2560000 --pbkdf=argon2id -i 15000 -s 512 -h sha256 -c aes-xts-plain64' - # Timestamp in a machine-sortable form alias tstamp="date '+%Y%m%d-%H%M%S'" @@ -13,12 +10,6 @@ alias mdcode="sed 's/^/ /'" # Intel format plz alias objdump="command objdump -M intel" -# Drop caches for swap issues -alias drop_caches="echo 3 | sudo /usr/bin/tee /proc/sys/vm/drop_caches" - -# dump acpi temperature -alias gettemp='printf "%02.2f\n" "$(cat /sys/class/thermal/thermal_zone0/temp)e-3"' - # get git working directory alias gitroot="git rev-parse --show-toplevel" @@ -31,20 +22,37 @@ alias ipy="ipython3 --no-banner" # Skip the header on bc alias bc="command bc -q" -# Get a decently readable df -alias dfh="df -h -x tmpfs -x devtmpfs -x squashfs -x fuse -x efivarfs" - # Clear the GPG agent alias clear-gpg-agent="echo RELOADAGENT | gpg-connect-agent" -# Battery details -alias bat-details='upower -i $(upower -e | grep battery)' - -# Nvidia refresh rate -alias nvidia-refresh-rate='nvidia-settings --display=:0 -q RefreshRate -t' - # Earthly ssh alias earthly='earthly --ssh-auth-sock ""' -# to clipboard -alias toclip='xclip -selection clipboard' +if [ "$(uname)" = "Linux" ]; then + # Cryptsetup alias + alias luksFormat='cryptsetup luksFormat --type=luks2 --pbkdf-memory=2560000 --pbkdf=argon2id -i 15000 -s 512 -h sha256 -c aes-xts-plain64' + + # Drop caches for swap issues + alias drop_caches="echo 3 | sudo /usr/bin/tee /proc/sys/vm/drop_caches" + + # dump acpi temperature + alias gettemp='printf "%02.2f\n" "$(cat /sys/class/thermal/thermal_zone0/temp)e-3"' + + # Get a decently readable df + alias dfh="df -h -x tmpfs -x devtmpfs -x squashfs -x fuse -x efivarfs" + + # Battery details + alias bat-details='upower -i $(upower -e | grep battery)' + + # Nvidia refresh rate + alias nvidia-refresh-rate='nvidia-settings --display=:0 -q RefreshRate -t' + + # to clipboard + alias toclip='xclip -selection clipboard' +elif [ "$(uname)" = "Darwin" ]; then + # Get a decently readable df + alias dfh="df -h" + + # to clipboard + alias toclip='pbcopy' +fi diff --git a/dotfiles/config/fish/conf.d/aliases.fish b/dotfiles/config/fish/conf.d/aliases.fish index 3e2ef70..176b188 100644 --- a/dotfiles/config/fish/conf.d/aliases.fish +++ b/dotfiles/config/fish/conf.d/aliases.fish @@ -1,6 +1,3 @@ -# Cryptsetup alias -alias luksFormat 'cryptsetup luksFormat --type=luks2 --pbkdf-memory=2560000 --pbkdf=argon2id -i 15000 -s 512 -h sha256 -c aes-xts-plain64' - # Timestamp in a machine-sortable form alias tstamp "date '+%Y%m%d-%H%M%S'" @@ -10,12 +7,6 @@ alias mdcode "sed 's/^/ /'" # Intel format plz alias objdump "command objdump -M intel" -# Drop caches for swap issues -alias drop_caches "echo 3 | sudo /usr/bin/tee /proc/sys/vm/drop_caches" - -# dump acpi temperature -alias gettemp 'printf "%02.2f\n" (cat /sys/class/thermal/thermal_zone0/temp)e-3' - # get git working directory alias gitroot "git rev-parse --show-toplevel" @@ -28,23 +19,40 @@ alias ipy "ipython3 --no-banner" # Skip the header on bc alias bc "command bc -q" -# Get a decently readable df -alias dfh "df -h -x tmpfs -x devtmpfs -x squashfs -x fuse -x efivarfs" - # Clear the GPG agent alias clear-gpg-agent "echo RELOADAGENT | gpg-connect-agent" -# Battery details -alias bat-details 'upower -i (upower -e | grep battery)' - -# Nvidia refresh rate -alias nvidia-refresh-rate 'nvidia-settings --display=:0 -q RefreshRate -t' - # Earthly ssh alias earthly 'earthly --ssh-auth-sock ""' -# to clipboard -alias toclip 'xclip -selection clipboard' +if test (uname) = "Linux" + # Cryptsetup alias + alias luksFormat 'cryptsetup luksFormat --type=luks2 --pbkdf-memory=2560000 --pbkdf=argon2id -i 15000 -s 512 -h sha256 -c aes-xts-plain64' + + # Drop caches for swap issues + alias drop_caches "echo 3 | sudo /usr/bin/tee /proc/sys/vm/drop_caches" + + # dump acpi temperature + alias gettemp 'printf "%02.2f\n" (cat /sys/class/thermal/thermal_zone0/temp)e-3' + + # Get a decently readable df + alias dfh "df -h -x tmpfs -x devtmpfs -x squashfs -x fuse -x efivarfs" + + # Battery details + alias bat-details 'upower -i (upower -e | grep battery)' + + # Nvidia refresh rate + alias nvidia-refresh-rate 'nvidia-settings --display=:0 -q RefreshRate -t' + + # to clipboard + alias toclip 'xclip -selection clipboard' +else if test (uname) = "Darwin" + # Get a decently readable df + alias dfh "df -h" + + # to clipboard + alias toclip 'pbcopy' +end # On some systems, bat is batcat if not command -v bat >/dev/null 2>&1 diff --git a/dotfiles/config/fish/config.fish b/dotfiles/config/fish/config.fish index 787f7e8..4230e88 100644 --- a/dotfiles/config/fish/config.fish +++ b/dotfiles/config/fish/config.fish @@ -34,4 +34,6 @@ end fish_add_path --move --path {$HOME}/bin if test (uname) = "Darwin" fish_add_path --move --path {$HOME}/bin/macos +else if test (uname) = "Linux" + fish_add_path --move --path {$HOME}/bin/linux end diff --git a/dotfiles/shenv b/dotfiles/shenv index 368dfd3..2afe628 100755 --- a/dotfiles/shenv +++ b/dotfiles/shenv @@ -194,6 +194,8 @@ if [ "$(uname)" = "Darwin" ] ; then export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-$TMPDIR/runtime-$(id -u)}" export XDG_STATE_HOME="${XDG_STATE_HOME:-$HOME/.local/state}" export PATH="${HOME}/bin/macos:${PATH}" +elif [ "$(uname)" = "Linux" ] ; then + export PATH="${HOME}/bin/linux:${PATH}" fi if test -e "$HOME/.localenv"; then diff --git a/dotfiles/tmux.conf b/dotfiles/tmux.conf index 1b89759..b9ced0e 100644 --- a/dotfiles/tmux.conf +++ b/dotfiles/tmux.conf @@ -45,7 +45,7 @@ set -g window-status-current-style fg=colour235,bg=colour33,bold set -g status-interval 60 set -g status-left-length 30 set -g status-left '/#h: #S/ ' -set -g status-right '#{?pane_title,/#{pane_title}/ ,}#(cut -d " " -f 1-3 /proc/loadavg)#[default] #[fg=colour166]%H:%M#[default]' +set -g status-right '#{?pane_title,/#{pane_title}/ ,}#(uptime | rev | cut -d":" -f1 | rev | sed s/,//g)#[default] #[fg=colour166]%H:%M#[default]' # Advanced mouse mode from http://tangledhelix.com/blog/2012/07/16/tmux-and-mouse-mode/ # Toggle mouse on @@ -65,8 +65,9 @@ bind M \ display 'Mouse: OFF' # tmux X clipboard integration -bind C-c run "tmux show-buffer | xsel -i -b" -bind C-v run "tmux set-buffer -- \"$(xsel -o -b)\"; tmux paste-buffer" +if-shell 'test "$(uname)" = "Darwin"' \ + 'bind C-c run "tmux show-buffer | pbcopy"; bind C-v run "tmux set-buffer -- \"$(pbpaste)\"; tmux paste-buffer"' \ + 'bind C-c run "tmux show-buffer | xsel -i -b"; bind C-v run "tmux set-buffer -- \"$(xsel -o -b)\"; tmux paste-buffer"' # List of plugins set -g @plugin 'tmux-plugins/tpm' diff --git a/dotfiles/zshrc b/dotfiles/zshrc index be26196..499aca0 100755 --- a/dotfiles/zshrc +++ b/dotfiles/zshrc @@ -289,6 +289,8 @@ fi PATH="${HOME}/bin:${PATH}" if [[ "$(uname)" == "Darwin" ]]; then PATH="${HOME}/bin/macos:${PATH}" +elif [[ "$(uname)" == "Linux" ]]; then + PATH="${HOME}/bin/linux:${PATH}" fi # Load any local settings diff --git a/dotfiles/zshrc.d/alert.zsh b/dotfiles/zshrc.d/alert.zsh index 7eab354..4ddd99e 100644 --- a/dotfiles/zshrc.d/alert.zsh +++ b/dotfiles/zshrc.d/alert.zsh @@ -18,8 +18,15 @@ alert() { icon="error" fi - # Send the notification with the executed command - notify-send --urgency=low -i "$icon" "Finished: '$@'" + if [ "$(uname)" = "Darwin" ]; then + # macOS notification + local title="Finished: '$*'" + local msg="Exit code: $ret" + osascript -e "display notification \"$msg\" with title \"$title\"" + else + # Send the notification with the executed command + notify-send --urgency=low -i "$icon" "Finished: '$@'" + fi # Return the original exit code return $ret diff --git a/dotfiles/zshrc.d/android.zsh b/dotfiles/zshrc.d/android.zsh index c8810b8..28687d1 100644 --- a/dotfiles/zshrc.d/android.zsh +++ b/dotfiles/zshrc.d/android.zsh @@ -1,7 +1,12 @@ -ANDROID_HOME=$HOME/Library/Android/sdk +if [ "$(uname)" = "Darwin" ]; then + ANDROID_HOME=$HOME/Library/Android/sdk +else + ANDROID_HOME=$HOME/Android/Sdk +fi -if test -d $ANDROID_HOME ; then - PATH=$PATH:$ANDROID_HOME/emulator:$ANDROID_HOME/platform-tools +if test -d "${ANDROID_HOME}" ; then + export ANDROID_HOME + PATH="${PATH}:${ANDROID_HOME}/emulator:${ANDROID_HOME}/platform-tools" else unset ANDROID_HOME fi diff --git a/dotfiles/zshrc.d/assemble.zsh b/dotfiles/zshrc.d/assemble.zsh index 3677c91..8763972 100644 --- a/dotfiles/zshrc.d/assemble.zsh +++ b/dotfiles/zshrc.d/assemble.zsh @@ -6,7 +6,11 @@ if have_command nasm && have_command objdump ; then local TMPF=`mktemp` local bytes local byte - $NASM -f elf -o $TMPF $1 + local format="elf" + if [[ "$OSTYPE" == darwin* ]]; then + format="macho64" + fi + $NASM -f $format -o $TMPF $1 $OBJDUMP -M intel -d $TMPF | grep '^ ' | cut -f2 | while read -A bytes ; do for byte in $bytes ; do echo -n "\\\\x$byte" diff --git a/dotfiles/zshrc.d/functions.zsh b/dotfiles/zshrc.d/functions.zsh index 8254646..db8188f 100644 --- a/dotfiles/zshrc.d/functions.zsh +++ b/dotfiles/zshrc.d/functions.zsh @@ -1,5 +1,11 @@ function dumpenv { - tr '\0' '\n' < /proc/${1}/environ + if [ "$(uname)" = "Linux" ]; then + tr '\0' '\n' < /proc/${1}/environ + elif [ "$(uname)" = "Darwin" ]; then + # macOS doesn't have /proc, use ps instead. + # Note: this may truncate if environment is very large. + ps -p ${1} -wwwe -o command= | tr ' ' '\n' | grep '=' + fi } if test -x "/sbin/starship" ; then diff --git a/dotfiles/zshrc.d/lesshighlight.zsh b/dotfiles/zshrc.d/lesshighlight.zsh index 99c466a..eeff672 100644 --- a/dotfiles/zshrc.d/lesshighlight.zsh +++ b/dotfiles/zshrc.d/lesshighlight.zsh @@ -1,8 +1,20 @@ -test -f /usr/share/source-highlight/src-hilite-lesspipe.sh && \ +# Find src-hilite-lesspipe.sh +_SRCHILITE="" +for _p in /usr/share/source-highlight/src-hilite-lesspipe.sh /opt/homebrew/bin/src-hilite-lesspipe.sh /usr/local/bin/src-hilite-lesspipe.sh ; do + if [ -f "$_p" ] ; then + _SRCHILITE="$_p" + break + fi +done + +if [ -n "$_SRCHILITE" ] ; then function srcless { if [ $# -ne 1 ] ; then - echo "$0 " > /dev/stderr + echo "Usage: srcless " > /dev/stderr return 1 fi - /usr/share/source-highlight/src-hilite-lesspipe.sh $1 | less -R + "$_SRCHILITE" "$1" | less -R } +fi + +unset _SRCHILITE _p