Skip to content

Commit d0e3778

Browse files
fix: Python 3 compatibility and misc improvements
Python 3 fixes: - bin/git-open: Use python3 shebang, decode bytes, add error handling - bin/tweet: Use python3 shebang, fix print() syntax, proper exit code - .aliases: Change python to python3 in Django and Docker aliases - .functions: Change dj() to use python3 Bug fixes: - .functions: Replace undefined print_error with echo - .functions: Add pygmentize availability check in json() - .profile: Add existence checks for OS-specific files, use $HOME - .zshrc: Fix duplicate powerlevel10k loading, add file check - bin/git-flake8: Add missing shebang - bin/splash: Fix typo 'coway' to 'cowsay' Deprecations: - bin/gitio: Mark as deprecated (git.io shut down in 2022) - setup/requirements.pip: Remove pinned ansible 2.3.2.0 (EOL), use latest - setup/requirements.pip: Remove deprecated piprot
1 parent b817b82 commit d0e3778

File tree

10 files changed

+67
-74
lines changed

10 files changed

+67
-74
lines changed

.aliases

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ 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 python "{}" runserver \;'
12-
alias djsu='find . -maxdepth 2 -name 'manage.py' -exec python "{}" createsuperuser --email="[email protected]" \;'
13-
alias djmm='find . -maxdepth 2 -name 'manage.py' -exec python "{}" makemigrations \;'
14-
alias djmig='find . -maxdepth 2 -name 'manage.py' -exec python "{}" migrate \;'
15-
alias djsh='find . -maxdepth 2 -name manage.py -exec python "{}" shell \;'
16-
alias djshp='find . -maxdepth 2 -name manage.py -exec python "{}" shell_plus --print-sql \;'
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="[email protected]" \;'
13+
alias djmm='find . -maxdepth 2 -name 'manage.py' -exec python3 "{}" makemigrations \;'
14+
alias djmig='find . -maxdepth 2 -name 'manage.py' -exec python3 "{}" migrate \;'
15+
alias djsh='find . -maxdepth 2 -name manage.py -exec python3 "{}" shell \;'
16+
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

@@ -81,8 +81,8 @@ alias reboot='sudo reboot'
8181
# ----------------------------------------------------------------------------
8282
# | Docker |
8383
# ----------------------------------------------------------------------------
84-
alias dcdjmm='docker-compose -f local.yml run django python manage.py makemigrations'
85-
alias dcdjmig='docker-compose -f local.yml run django python manage.py migrate'
84+
alias dcdjmm='docker-compose -f local.yml run django python3 manage.py makemigrations'
85+
alias dcdjmig='docker-compose -f local.yml run django python3 manage.py migrate'
8686
alias dcup='docker-compose -f local.yml up'
8787

8888
# ----------------------------------------------------------------------------

.functions

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function dj() {
1717
# e.g. dj migrate
1818
# dj runserver
1919
# dj collectstatic --noinput
20-
find . -maxdepth 2 -name 'manage.py' -exec python "{}" "$@" \;
20+
find . -maxdepth 2 -name 'manage.py' -exec python3 "{}" "$@" \;
2121
}
2222

2323
function chpwd() {
@@ -56,7 +56,7 @@ datauri() {
5656
"$mimeType" \
5757
"$(openssl base64 -in "$1" | tr -d "\n")"
5858
else
59-
print_error "'$1' is not a file."
59+
echo "Error: '$1' is not a file." >&2
6060
fi
6161
}
6262

@@ -143,10 +143,17 @@ function l () {
143143
# Syntax-highlight JSON strings or files
144144
# Usage: `json '{"foo":42}'` or `echo '{"foo":42}' | json`
145145
function json() {
146+
local output
146147
if [ -t 0 ]; then # argument
147-
python3 -mjson.tool <<< "$*" | pygmentize -l javascript
148+
output=$(python3 -mjson.tool <<< "$*")
148149
else # pipe
149-
python3 -mjson.tool | pygmentize -l javascript
150+
output=$(python3 -mjson.tool)
151+
fi
152+
# Use pygmentize if available, otherwise just print
153+
if command -v pygmentize &> /dev/null; then
154+
echo "$output" | pygmentize -l javascript
155+
else
156+
echo "$output"
150157
fi
151158
}
152159

.profile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ for file in ~/.{exports,aliases,functions,extra}; do
55
done
66
unset file
77

8-
# Detect and load OS specific settigs
8+
# Detect and load OS specific settings
99
platform='unknown'
10-
unamestr=`uname`
10+
unamestr=$(uname)
1111
if [[ "$unamestr" == 'Linux' ]]; then
12-
source ~/.linux
12+
[ -r ~/.linux ] && source ~/.linux
1313
elif [[ "$unamestr" == 'FreeBSD' ]]; then
14-
source ~/.freebsd
14+
[ -r ~/.freebsd ] && source ~/.freebsd
1515
elif [[ "$unamestr" == 'Darwin' ]]; then
16-
source ~/.osx
16+
[ -r ~/.osx ] && source ~/.osx
1717
fi
1818

1919
# Check for startup SPLASH script
@@ -31,4 +31,4 @@ export PATH="$HOME/.cargo/bin:$PATH"
3131
# Generated for envman. Do not edit.
3232
[ -s "$HOME/.config/envman/load.sh" ] && source "$HOME/.config/envman/load.sh"
3333

34-
export PATH="$PATH:/Users/$(whoami)/Downloads/flutter/bin"
34+
export PATH="$PATH:$HOME/Downloads/flutter/bin"

.zshrc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ fi
77

88

99
ZSH=$HOME/.oh-my-zsh
10-
ZSH_THEME="powerlevel10k/powerlevel10k"
10+
# Theme is sourced directly from ~/powerlevel10k below
11+
ZSH_THEME=""
1112
source $ZSH/oh-my-zsh.sh
1213

1314
# Customizations goes below
@@ -38,7 +39,9 @@ export PATH="$PATH:$HOME/.rvm/bin"
3839

3940
# Enable buildpack `packs` completion for docker
4041
command -v pack >/dev/null && . "$(pack completion --shell zsh)"
41-
source ~/powerlevel10k/powerlevel10k.zsh-theme
42+
43+
# Load Powerlevel10k theme
44+
[[ -f ~/powerlevel10k/powerlevel10k.zsh-theme ]] && source ~/powerlevel10k/powerlevel10k.zsh-theme
4245

4346
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
4447
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh

bin/git-flake8

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/bin/bash
12
echo "#!/bin/sh" > .git/hooks/pre-commit
23
echo "flake8 ." >> .git/hooks/pre-commit
34
chmod a+x .git/hooks/pre-commit

bin/git-open

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python3
22

33
import subprocess
44
import webbrowser
5+
import sys
6+
7+
try:
8+
remote_url = subprocess.check_output(['git', 'config', '--get', 'remote.origin.url']).decode('utf-8').strip()
9+
branch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']).decode('utf-8').strip()
10+
except subprocess.CalledProcessError:
11+
print("Error: Not a git repository or no remote origin configured")
12+
sys.exit(1)
513

6-
remote_url = subprocess.check_output(['git', 'config', '--get', 'remote.origin.url']).strip()
7-
branch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']).strip()
814
url = None
915

1016

bin/gitio

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,27 @@
11
#!/bin/bash
22

3+
# NOTE: git.io was deprecated by GitHub in 2022 and no longer works.
4+
# This script is kept for reference but will not function.
5+
# Consider using alternatives like:
6+
# - GitHub's own short URLs (github.com/user/repo)
7+
# - bit.ly, tinyurl.com, or other URL shorteners
8+
39
function _gitio() {
410

511
if [[ "$1" == "-h" || "$1" == "--help" ]]; then cat <<HELP
6-
gitio
7-
http://git.io
8-
9-
Usage: gitio <url> [slug]
10-
11-
Shorten github url and copies it to clipboard.
12-
13-
url (Required) Any github url
14-
15-
slug (Optional) The shortname that you want to use. If not provided randomly generated shortname is returned.
12+
gitio (DEPRECATED)
1613
17-
Dependencies
14+
NOTE: git.io was shut down by GitHub in 2022. This script no longer works.
1815
19-
curl, pbcopy/xclip
16+
Consider using alternative URL shorteners like bit.ly or tinyurl.
2017
21-
Copyright (c) 2013 "theskumar" Saurabh Kumar
22-
Licensed under the MIT license.
18+
Original usage was: gitio <url> [slug]
2319
HELP
2420
return; fi
2521

26-
if [ ! "$1" ]; then
27-
echo 'You must specify one or more parameter to run.'
28-
return 1
29-
fi
30-
31-
if [ -z "$2" ] ; then
32-
t=$(curl -s -i http://git.io/ -F "url=${1}" 2> /dev/null)
33-
else
34-
t=$(curl -s -i http://git.io/ -F "url=${1}" -F "code=${2}" 2> /dev/null)
35-
fi
36-
37-
echo "$t" | grep 'Status'
38-
status_code=$(echo "$t" | grep 'Status' | cut -d' ' -f 2)
39-
local status_code
40-
if [ "$status_code" = "201" ] ; then
41-
short_url=$(echo "$t" | grep 'Location' | cut -d' ' -f 2)
42-
echo "$short_url"
43-
44-
copied="Short URL copied to clipboard!"
45-
command -v pbcopy >& /dev/null && echo "$short_url" | pbcopy && echo "$copied"
46-
command -v xclip >& /dev/null && echo "$short_url" | xclip -selection clipboard && echo "$copied"
47-
fi
22+
echo "Error: git.io service was deprecated by GitHub in 2022."
23+
echo "This script no longer works. Consider using bit.ly or tinyurl.com instead."
24+
return 1
4825
}
4926

5027
# By putting the above code inside a function, if this file is sourced (which

bin/splash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ if hash cowsay 2>/dev/null; then
2020
cowsay "$text"
2121
fi
2222
else
23-
echo "Install fortune and coway to turn me into speak wizard. (!)"
23+
echo "Install fortune and cowsay to turn me into speak wizard. (!)"
2424
fi
2525
}
2626

bin/tweet

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22

33
import os
44
import sys
55
import tweepy
66

77
try:
8-
CONSUMER_KEY = os.environ['TWITTER_CONSUMER_KEY']
9-
CONSUMER_SECRET = os.environ['TWITTER_CONSUMER_SECRET']
10-
ACCESS_KEY = os.environ['TWITTER_ACCESS_KEY']
11-
ACCESS_SECRET = os.environ['TWITTER_ACCESS_SECRET']
8+
CONSUMER_KEY = os.environ['TWITTER_CONSUMER_KEY']
9+
CONSUMER_SECRET = os.environ['TWITTER_CONSUMER_SECRET']
10+
ACCESS_KEY = os.environ['TWITTER_ACCESS_KEY']
11+
ACCESS_SECRET = os.environ['TWITTER_ACCESS_SECRET']
1212
except KeyError:
13-
print "Environment Variables couldn't be read."
14-
exit
13+
print("Environment Variables couldn't be read.")
14+
sys.exit(1)
1515

1616

1717
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
1818
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
19-
print "connecting..."
19+
print("connecting...")
2020
api = tweepy.API(auth)
2121

2222
result = api.update_status(sys.argv[1])
23-
print "https://twitter.com/{screen_name}/status/{status_id}".format(
24-
screen_name=result.user.screen_name,
25-
status_id=result.id
26-
)
23+
print("https://twitter.com/{screen_name}/status/{status_id}".format(
24+
screen_name=result.user.screen_name,
25+
status_id=result.id
26+
))

setup/requirements.pip

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ fabric
66
cookiecutter
77
virtualenv
88
ghp-import
9-
piprot
109
html2text
1110
requests[security]
12-
ansible==2.3.2.0
11+
ansible

0 commit comments

Comments
 (0)