Merge branch 'master' of github.com:hykilpikonna/zshrc

This commit is contained in:
Azalea
2022-12-10 10:23:03 -05:00
7 changed files with 1165 additions and 35 deletions
+89
View File
@@ -0,0 +1,89 @@
#!/usr/bin/env python3
import argparse
import json
import sys
from pathlib import Path
from subprocess import check_output
CONFIG = Path.home() / ".config" / "git-ids.json"
def load() -> dict[str, list[str]]:
if not CONFIG.is_file():
return {}
return json.loads(CONFIG.read_text())
def store(d: dict[str, list[str]]):
CONFIG.parent.mkdir(parents=True, exist_ok=True)
CONFIG.write_text(json.dumps(d, indent=2))
print("Saved.")
def cmd_get(args: argparse.Namespace):
n = load().get(args.alias)
if n is None:
exit(128)
print("\n".join(n))
def cmd_add(args: argparse.Namespace):
store({args.alias: [args.name, args.email], **load()})
def cmd_add_all(_):
f = load()
log = check_output('git log --pretty="%an%n%ae%n%n"', shell=True).decode().strip().split("\n\n")
log = {tuple(l.strip().split('\n')) for l in log}
log = {l for l in log if l not in f.values()}
print(log)
# Filter out no-reply
new_log = []
for n, _ in log:
same_name = [(n1, e) for n1, e in log if n1 == n]
filtered = [(n, e) for n, e in same_name if "noreply.github.com" not in e]
if len(filtered):
new_log += filtered
else:
new_log += same_name
log = new_log
for l in log:
a = input(f"Do you want {l} to be added?\nType in an alias if yes, otherwise type enter.\n> ").strip()
if a:
f[a] = l
store(f)
def cmd_list(_):
print("\n".join(f"{n}: {e[0]}, {e[1]}" for n, e in load().items()))
if __name__ == '__main__':
raw_args = sys.argv[1:]
if not raw_args:
raw_args = ['-h']
par = argparse.ArgumentParser("Git ID List")
sp = par.add_subparsers()
get = sp.add_parser("get", usage="Get an identity")
get.set_defaults(handler=cmd_get)
get.add_argument("alias", help="Alias of the author")
add = sp.add_parser("add", usage="Add an identity")
add.set_defaults(handler=cmd_add)
add.add_argument("alias", help="Short alias of the author")
add.add_argument("name", help="Name shown in git log")
add.add_argument("email", help="Email shown in git log")
add = sp.add_parser("add-all", usage="Ask to add each identity from current git log")
add.set_defaults(handler=cmd_add_all)
add = sp.add_parser("list", usage="List identities")
add.set_defaults(handler=cmd_list)
args = par.parse_args(raw_args)
if hasattr(args, "handler"):
args.handler(args)
+1
View File
@@ -48,4 +48,5 @@ check-ssh-config
# Check nanorc includes
# check-inject "$HOME/.nanorc" "include $SCR/../config-sync/nanorc"
check-config "$HOME/.nanorc" "$CFGSYNC/nanorc"
check-config "$HOME/.condarc" "$CFGSYNC/.condarc"
check-config "$HOME/.java/.userPrefs/com/cburch/logisim/prefs.xml" "$CFGSYNC/.java/.userPrefs/com/cburch/logisim/prefs.xml"
+23 -20
View File
@@ -19,23 +19,26 @@ pcolor() {
prompt "$tmp" color
}
########### Build a zsh prompt
# New line first
prompt-set 0 "&n"
# Time stamp
prompt-set 10 "&5%D{%a %m-%d %H:%M}&r "
[[ "$HOST" != "HyDEV" ]] && prompt-set 10 "&gf(#55CDFC)%D{%a} &gf(#F7A8B8)%D{%m-}&f%D{%d} &gf(#F7A8B8)%D{%H:}&gf(#55CDFC)%D{%M}&r "
# Hostname
prompt-set 20 "&1%m&r "
[[ "$HOST" == "HyDEV" ]] && prompt-set 20 "&gf(#55CDFC)H&gf(#F7A8B8)y&fD&gf(#F7A8B8)E&gf(#55CDFC)V&r "
# Username, or show a cat if I'm hykilpikonna
prompt-set 30 "&e%n&r "
[[ "$USER" == "hykilpikonna" ]] && prompt-set 30 "🐱 "
# Directory
prompt-set 40 "&r%~ "
# New line after the prompt header
prompt-set 1000 "&n"
# Prompt before input
prompt-set 1100 "> "
# Create prompt
prompt-update
# Build a zsh prompt
prompt-reset() {
# New line first
prompt-set 0 "&n"
# Time stamp
prompt-set 10 "&5%D{%a %m-%d %H:%M}&r "
[[ "$HOST" != "HyDEV" ]] && prompt-set 10 "&gf(#55CDFC)%D{%a} &gf(#F7A8B8)%D{%m-}&f%D{%d} &gf(#F7A8B8)%D{%H:}&gf(#55CDFC)%D{%M}&r "
# Hostname
prompt-set 20 "&1%m&r "
[[ "$HOST" == "HyDEV" ]] && prompt-set 20 "&gf(#55CDFC)H&gf(#F7A8B8)y&fD&gf(#F7A8B8)E&gf(#55CDFC)V&r "
# Username, or show a cat if I'm hykilpikonna
prompt-set 30 "&e%n&r "
[[ "$USER" == "hykilpikonna" ]] && prompt-set 30 "🐱 "
# Directory
prompt-set 40 "&r%~ "
# New line after the prompt header
prompt-set 1000 "&n"
# Prompt before input
prompt-set 1100 "> "
# Create prompt
prompt-update
}
prompt-reset
+77 -14
View File
@@ -4,6 +4,8 @@ HISTSIZE=1000
SAVEHIST=1000
setopt appendhistory
BASEDIR="$(dirname "$(dirname "$0")")"
# Modern unix replacements.
# Usage: modern-replace 'orig cmd' 'new cmd' 'orig cmd with args (optional)' 'new cmd with args (optional)'
modern-replace() {
@@ -13,9 +15,9 @@ modern-replace() {
new_cmd_with_args="${4:-$2}"
if command -v "$new_cmd" &> /dev/null; then
alias $orig_cmd="$new_cmd_with_args"
alias "$orig_cmd=$new_cmd_with_args"
else
alias $orig_cmd="$orig_cmd_with_args"
alias "$orig_cmd=$orig_cmd_with_args"
fi
}
@@ -26,12 +28,15 @@ modern-replace 'man' 'tldr'
modern-replace 'top' 'btop'
modern-replace 'ping' 'gping'
modern-replace 'dig' 'dog'
modern-replace 'grep' 'rg'
# modern-replace 'curl' 'curlie'
# modern-replace 'tree' 'broot'
source "$BASEDIR/plugins/zsh-z.plugin.zsh"
# Initialize fuck
if command -v 'fuck' &> /dev/null; then
eval $(thefuck --alias)
eval "$(thefuck --alias)"
fi
if command -v 'xdg-open' &> /dev/null; then
@@ -97,6 +102,12 @@ compress-zst() {
}
alias tar-kill-progress="watch -n 60 killall tar -SIGUSR1"
# Gradle with auto environment detection
GRADLE="$(which gradle)"
gradle() {
[[ -f "./gradlew" ]] && ./gradlew "$@" || $GRADLE "$@"
}
# Unix permissions reset (Dangerous! This will make executable files no longer executable)
reset-permissions-dangerous() {
sudo find . -type d -exec chmod 755 {} \;
@@ -111,7 +122,7 @@ export MAMBA_ROOT_PREFIX="$HOME/.conda"
# Mamba initialize function
mamba-init()
{
export MAMBA_EXE="$HOME/.local/bin/micromamba";
export MAMBA_EXE="$(which micromamba)";
__mamba_setup="$("$MAMBA_EXE" shell hook --shell zsh --prefix "$HOME/micromamba" 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__mamba_setup"
@@ -125,6 +136,11 @@ mamba-init()
unset __mamba_setup
}
# Auto init mamba
if command -v 'micromamba' &> /dev/null; then
mamba-init
fi
# Pyenv
if command -v 'pyenv' &> /dev/null; then
eval "$(pyenv init -)"
@@ -156,10 +172,10 @@ addline() {
# Silent pushd and popd
spushd () {
pushd "$@" > /dev/null
pushd "$@" > /dev/null || exit
}
spopd () {
popd "$@" > /dev/null
popd "$@" > /dev/null || exit
}
# Minecraft coloring
@@ -206,6 +222,53 @@ setproxy() {
prompt-update
}
# Git identity
git-ida() {
# Zsh only
TMP_ARR=("${(@f)$(git-id-list get "$1")}")
git-id "${TMP_ARR[1]}" "${TMP_ARR[2]}"
}
git-id() {
export GIT_USER="$1"
export GIT_EMAIL="$2"
git-id-prompt
}
git-id-prompt() {
if [[ -z "$GIT_USER" ]] && [[ -z "$GIT_EMAIL" ]]; then
prompt-reset
else
prompt-set 30 "&cGit ID: $GIT_USER | $GIT_EMAIL "
prompt-update
fi
}
git-id-prompt
GIT_BIN=$(which git)
git() {
if [[ -z "$GIT_USER" ]]; then
$GIT_BIN "$@"
else
$GIT_BIN -c "user.name=$GIT_USER" -c "user.email=$GIT_EMAIL" -c "commit.gpgsign=false" "$@"
fi
}
# Git environment
git-env() {
git_commands=( add bisect branch checkout clone commit diff fetch grep init log merge pull push rebase reset restore show status tag )
for i in "${git_commands[@]}"
do
alias "$i"="git $i"
done
alias 'grm'='git rm'
alias 'gmv'='git mv'
}
git-unenv() {
git_commands=( add bisect branch checkout clone commit diff fetch grep init log merge pull push rebase reset restore show status tag grm gmv )
for i in "${git_commands[@]}"
do
unalias "$i"
done
}
# Mac hostname
mac-hostname() {
name="$@"
@@ -218,17 +281,17 @@ mac-hostname() {
cut() {
if [ "$#" -lt 2 ]; then
echo "Usage: cut <file name> <end time (hh:mm:ss)> [start time (00:00:00)]"
return -1
return 2
fi
local start="${3:-00:00:00}"
echo $1
echo $2
echo $start
ffmpeg -i $1 -codec copy -ss $start -t $2 Cut\ $1
echo "$1"
echo "$2"
echo "$start"
ffmpeg -i "$1" -codec copy -ss "$start" -t "$2" Cut\ "$1"
}
alias vcomp="$SCR/helpers/video.py"
alias vcompy="ipython -i $SCR/helpers/video.py"
alias vcomp="$BASEDIR/scripts/helpers/video.py"
alias vcompy="ipython -i $BASEDIR/scripts/helpers/video.py"
# include if it exists
[ -f $HOME/extra.rc.sh ] && . $HOME/extra.rc.sh
[ -f "$HOME/extra.rc.sh" ] && . "$HOME/extra.rc.sh"