Skip to content

Commit 904ca08

Browse files
fix: modernize dotfiles and fix various bugs
- batcharge.py: fix parsing for new macOS battery format - bin/f: add missing shebang - bin/tor.sh: quote variables - bin/crlf.sh: quote variables, cross-platform sed - bin/git-open: add GitLab/Bitbucket support, remove hardcoded domain - bin/push: modernize git branch detection - bin/splash: fix cowfile check syntax - .aliases: fix shell syntax error - .exports: fix empty LC_ALL - .functions: quote variables, fix typos - .gitconfig: dynamic default branch detection - .gdbinit: comment out hardcoded path - .wgetrc: update to modern user agent - .zshrc: dynamic terraform path - .osx: remove npm anti-pattern - bootstrap.sh: fix typo - setup_mac.sh: fix requirements.pip path - setup_fedora.sh: fix typos, pgadmin4, mkdir before tar - osx_defaults.sh: remove defunct userscripts.org - vscode: remove version-specific extension path - requirements.pip: remove deprecated packages
1 parent 1c30f41 commit 904ca08

23 files changed

+122
-88
lines changed

.aliases

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@ sed 's/$/ --force/' |
88
sed '\$!s/$/ \&/' > ~/dotfiles/setup/vscode/install-extensions.sh"
99

1010
# Django Stuff
11-
alias djrun='find . -maxdepth 2 -name 'manage.py' -exec python3 "{}" runserver \;'
12-
alias djsu='find . -maxdepth 2 -name 'manage.py' -exec python3 "{}" createsuperuser --email="admin@localhost.com" \;'
13-
alias djmm='find . -maxdepth 2 -name 'manage.py' -exec python3 "{}" makemigrations \;'
14-
alias djmig='find . -maxdepth 2 -name 'manage.py' -exec python3 "{}" migrate \;'
11+
alias djrun='find . -maxdepth 2 -name "manage.py" -exec python3 "{}" runserver \;'
12+
alias djsu='find . -maxdepth 2 -name "manage.py" -exec python3 "{}" createsuperuser --email="admin@localhost.com" \;'
13+
alias djmm='find . -maxdepth 2 -name "manage.py" -exec python3 "{}" makemigrations \;'
14+
alias djmig='find . -maxdepth 2 -name "manage.py" -exec python3 "{}" migrate \;'
1515
alias djsh='find . -maxdepth 2 -name manage.py -exec python3 "{}" shell \;'
1616
alias djshp='find . -maxdepth 2 -name manage.py -exec python3 "{}" shell_plus --print-sql \;'
1717

1818
alias pepfix='autopep8 --max-line-length=120 -i'
1919

2020
# Virtualenv
21-
alias sv='if [[ ! -d "venv" && ! -L "venv" ]] ; then; virtualenv -p $(command -v python3) venv; touch requirements.txt; fi; source venv/bin/activate; export PS1="(${${PWD##*/}:0:5}…/venv)$_OLD_VIRTUAL_PS1"'
21+
alias sv='if [[ ! -d "venv" && ! -L "venv" ]]; then virtualenv -p $(command -v python3) venv; touch requirements.txt; fi; source venv/bin/activate; export PS1="(${${PWD##*/}:0:5}…/venv)$_OLD_VIRTUAL_PS1"'
2222
alias sv3=sv
2323
# Note: sv2 removed - Python 2 reached end of life in 2020
2424

2525
# ------------------------------------------------------------------------------
2626
# | Git Commands |
2727
# ------------------------------------------------------------------------------
28-
# Undo a `git push`
29-
alias undopush="git push -f origin HEAD^:master"
28+
# Undo a `git push` (uses default branch)
29+
alias undopush='git push -f origin HEAD^:$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed "s@^refs/remotes/origin/@@" || echo "main")'
3030

3131
alias gp='git push origin HEAD'
3232
alias gpf='git push origin HEAD --force-with-lease'
@@ -40,9 +40,9 @@ alias gs='git status'
4040
alias gcl='git clone'
4141
alias gcm='git commit -m'
4242
alias gaa='git add :/; git status -sb'
43-
# Updates master of upstream project and falls back to your patch branch
43+
# Updates default branch of upstream project and falls back to your patch branch
4444
# so that you can start rebasing/merging
45-
alias gsync='git checkout master;git pull upstream master;git push origin master; git checkout -'
45+
alias gsync='default_branch=$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed "s@^refs/remotes/origin/@@" || echo "main"); git checkout $default_branch; git pull upstream $default_branch; git push origin $default_branch; git checkout -'
4646

4747
# ------------------------------------------------------------------------------
4848
# | Network |

.exports

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ export LC_MESSAGES="en_US.UTF-8"
3535
export LC_MONETARY="en_US.UTF-8"
3636
export LC_NUMERIC="en_US.UTF-8"
3737
export LC_TIME="en_US.UTF-8"
38-
export LC_ALL=
38+
# LC_ALL intentionally not set - allows individual LC_* variables to take effect
39+
# export LC_ALL="en_US.UTF-8" # Uncomment to override all locale settings
3940

4041

4142
export PYTHONHASHSEED=random

.functions

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# list/describe ec2 instances in all the regions
22
function ec2-list-all(){
3-
for region in `aws ec2 describe-regions --output text | cut -f3`
3+
for region in $(aws ec2 describe-regions --output text | cut -f3)
44
do
55
echo -e "\nListing Instances in region:'$region'..."
66
echo -e "https://console.aws.amazon.com/ec2/v2/home?region=$region"
7-
aws ec2 describe-instances --region $region | jq '.Reservations[] | ( .Instances[] | {state: .State.Name, name: .KeyName, type: .InstanceType, key: .KeyName})'
7+
aws ec2 describe-instances --region "$region" | jq '.Reservations[] | ( .Instances[] | {state: .State.Name, name: .KeyName, type: .InstanceType, key: .KeyName})'
88
done
99
}
1010

1111
function svg-to-base64() {
12-
echo "background: transparent url('data:image/svg+xml;base64,"$(openssl base64 < $@)"') no-repeat center center;"
12+
echo "background: transparent url('data:image/svg+xml;base64,$(openssl base64 < "$@")') no-repeat center center;"
1313
}
1414

1515
function dj() {
@@ -32,7 +32,7 @@ function chpwd() {
3232
# ------------------------------------------------------------------------------
3333

3434
openssl-to-pem () {
35-
openssl pkcs12 -in $1 -out $1.pem -nodes -clcerts
35+
openssl pkcs12 -in "$1" -out "$1.pem" -nodes -clcerts
3636
}
3737

3838
# ------------------------------------------------------------------------------
@@ -85,8 +85,8 @@ supertouch() {
8585

8686
# Create a .tar.gz archive, using `zopfli`, `pigz` or `gzip` for compression
8787
function targz() {
88-
local tmpFile="${@%/}.tar"
89-
tar -cvf "${tmpFile}" --exclude=".DS_Store" "${@}" || return 1
88+
local tmpFile="${*%/}.tar"
89+
tar -cvf "${tmpFile}" --exclude=".DS_Store" "$@" || return 1
9090

9191
size=$(
9292
stat -f"%z" "${tmpFile}" 2> /dev/null; # OS X `stat`
@@ -166,12 +166,12 @@ function fixcrlf(){
166166

167167
# Create new directories and enter the first one
168168
function md() {
169-
mkdir -pv "$@" && cd "$1"
169+
mkdir -pv "$@" && cd "$1" || return
170170
}
171171

172172
# Copy w/ progress
173173
cp_p () {
174-
rsync -WavP --human-readable --progress $1 $2
174+
rsync -WavP --human-readable --progress "$1" "$2"
175175
}
176176

177177
# ------------------------------------------------------------------------------
@@ -210,7 +210,7 @@ function phpserver() {
210210
# | Git |
211211
# ------------------------------------------------------------------------------
212212

213-
# function to normalize a crupt git repo
213+
# function to normalize a corrupt git repo
214214
function git_normalize_eol(){
215215
echo "* text=auto" >>.gitattributes
216216
rm .git/index # Remove the index to force git to
@@ -222,12 +222,12 @@ function git_normalize_eol(){
222222
}
223223

224224
function gitignore() {
225-
curl -s https://www.gitignore.io/api/$@;
225+
curl -s "https://www.gitignore.io/api/$*"
226226
}
227227

228228

229229
# take this repo and copy it to somewhere else minus the .git stuff.
230230
function gitexport(){
231231
mkdir -p "$1"
232-
git archive master | tar -x -C "$1"
232+
git archive HEAD | tar -x -C "$1"
233233
}

.gdbinit

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
add-auto-load-safe-path ~/personal/cpython/
1+
# Add CPython source directory for debugging (adjust path as needed)
2+
# add-auto-load-safe-path ~/personal/cpython/

.gitconfig

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
di = !"d() { git diff --patch-with-stat HEAD~$1; }; git diff-index --quiet HEAD -- || clear; d"
1414

1515
# Pull in remote changes for the current repository and all its submodules
16-
p = !"git pull; git submodule foreach git pull origin master"
16+
p = !"git pull; git submodule foreach git pull origin HEAD"
1717

1818
# Clone a repository including all submodules
1919
c = clone --recursive
@@ -60,12 +60,13 @@
6060
# List contributors with number of commits
6161
contributors = shortlog --summary --numbered
6262

63-
# Merge GitHub pull request on top of the `master` branch
63+
# Merge GitHub pull request on top of the default branch
6464
mpr = "!f() { \
65+
default_branch=$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's@^refs/remotes/origin/@@' || echo 'main'); \
6566
if [ $(printf \"%s\" \"$1\" | grep '^[0-9]\\+$' > /dev/null; printf $?) -eq 0 ]; then \
6667
git fetch origin refs/pull/$1/head:pr/$1 && \
67-
git rebase master pr/$1 && \
68-
git checkout master && \
68+
git rebase $default_branch pr/$1 && \
69+
git checkout $default_branch && \
6970
git merge pr/$1 && \
7071
git branch -D pr/$1 && \
7172
git commit --amend -m \"$(git log -1 --pretty=%B)\n\nCloses #$1.\"; \

.osx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ then
1111
fi
1212

1313
# Get OS X Software Updates, and update installed Ruby gems, Homebrew, npm, and their installed packages
14-
alias update='sudo softwareupdate -i -a; brew update; brew upgrade; brew cleanup; npm install npm -g; npm update -g; sudo gem update'
14+
alias update='sudo softwareupdate -i -a; brew update; brew upgrade; brew cleanup; npm update -g; sudo gem update'
1515

1616
# Empty the Trash on all mounted volumes and the main HDD
1717
alias emptytrash="sudo rm -rfv /Volumes/*/.Trashes; rm -rfv ~/.Trash"

.wgetrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ robots = off
3434
# Print the HTTP and FTP server responses
3535
server_response = on
3636

37-
# Disguise as IE 9 on Windows 7
38-
user_agent = Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
37+
# Use a modern user agent (Chrome on macOS)
38+
user_agent = Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36

.zshrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ command -v pack >/dev/null && . "$(pack completion --shell zsh)"
4646
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
4747

4848
autoload -U +X bashcompinit && bashcompinit
49-
complete -o nospace -C /usr/local/bin/terraform terraform
49+
# Terraform completion - auto-detect path for Intel/Apple Silicon Macs
50+
if command -v terraform &>/dev/null; then
51+
complete -o nospace -C "$(which terraform)" terraform
52+
fi
5053

5154
# Sign commits via GPG
5255
export GPG_TTY=$(tty)

bin/batcharge.py

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,50 @@
44
# saved to ~/bin/batcharge.py and from
55
# http://stevelosh.com/blog/2010/02/my-extravagant-zsh-prompt/#my-right-prompt-battery-capacity
66

7-
import math, subprocess
7+
import math
8+
import re
9+
import subprocess
10+
import sys
11+
12+
result = subprocess.run(
13+
["ioreg", "-rc", "AppleSmartBattery"],
14+
capture_output=True,
15+
text=True
16+
)
17+
output = result.stdout
18+
19+
# Match top-level "MaxCapacity" = <number> (not nested in BatteryData)
20+
# Use regex to find standalone capacity values
21+
max_match = re.search(r'^\s+"MaxCapacity"\s*=\s*(\d+)', output, re.MULTILINE)
22+
cur_match = re.search(r'^\s+"CurrentCapacity"\s*=\s*(\d+)', output, re.MULTILINE)
823

9-
p = subprocess.Popen(["ioreg", "-rc", "AppleSmartBattery"], stdout=subprocess.PIPE)
10-
output = p.communicate()[0]
24+
if not max_match or not cur_match:
25+
sys.exit(0) # No battery or can't parse
1126

12-
o_max = [l for l in output.splitlines() if b'MaxCapacity' in l][0]
13-
o_cur = [l for l in output.splitlines() if b'CurrentCapacity' in l][0]
27+
b_max = float(max_match.group(1))
28+
b_cur = float(cur_match.group(1))
1429

15-
b_max = float(o_max.rpartition(b'=')[-1].strip())
16-
b_cur = float(o_cur.rpartition(b'=')[-1].strip())
30+
if b_max == 0:
31+
sys.exit(0)
1732

1833
charge = b_cur / b_max
1934
charge_threshold = int(math.ceil(10 * charge))
2035

2136
# Output
22-
23-
total_slots, slots = 10, []
24-
filled = int(math.ceil(charge_threshold * (total_slots / 10.0))) * u'◼'
37+
total_slots = 10
38+
filled = int(math.ceil(charge_threshold * (total_slots / 10.0))) * '◼'
2539
# old arrow: ▹▸▶
26-
empty = (total_slots - len(filled)) * u'◻'
27-
28-
out = (filled + empty).encode('utf-8')
29-
import sys
40+
empty = (total_slots - len(filled)) * '◻'
3041

31-
color_green = '%{%}'
32-
color_yellow = '%{%}'
33-
color_red = '%{%}'
34-
color_reset = '%{%}'
42+
color_green = '%{[32m%}'
43+
color_yellow = '%{[33m%}'
44+
color_red = '%{[31m%}'
45+
color_reset = '%{[00m%}'
3546
color_out = (
3647
color_green if len(filled) > 6
3748
else color_yellow if len(filled) > 4
3849
else color_red
3950
)
4051

41-
out = str(color_out) + str(out) + str(color_reset)
52+
out = color_out + filled + empty + color_reset
4253
sys.stdout.write(out)

bin/crlf.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ function _crlf_file() {
1515
dos2unix "$1"
1616
else
1717
# Fallback: use sed if dos2unix is not installed
18-
sed -i'' -e 's/\r$//' "$1"
18+
# Use temp file for cross-platform compatibility (BSD vs GNU sed)
19+
sed 's/\r$//' "$1" > "$1.tmp" && mv "$1.tmp" "$1"
1920
fi
2021
fi
2122
fi
@@ -24,12 +25,12 @@ function _crlf_file() {
2425
# Single file
2526
if [ "$1" != "" ] && [ "$1" != "--force" ]; then
2627
[ "$2" == "--force" ] && force=1 || force=0
27-
_crlf_file "$1" $force
28+
_crlf_file "$1" "$force"
2829
exit 0
2930
fi
3031

3132
# All files
3233
[ "$1" == "--force" ] && force=1 || force=0
3334
for file in $(find . -type f -not -path "*/.git/*" -not -path "*/node_modules/*" -print0 | xargs -0 file | grep ASCII | cut -d: -f1); do
34-
_crlf_file "$file" $force
35+
_crlf_file "$file" "$force"
3536
done

0 commit comments

Comments
 (0)