inital commit
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
|
||||
.autoversion
|
||||
Executable
+8
@@ -0,0 +1,8 @@
|
||||
#!/bin/zsh
|
||||
|
||||
if [[ -n $VIRTUAL_ENV && ! -f "./$VENV_FILE_EXTENSION" ]]; then
|
||||
if [[ ! -e $(JUPYTER_PREFER_ENV_PATH=0 jupyter --data-dir)"/kernels/"$(basename "${VIRTUAL_ENV//%\/.venv/}") ]]; then
|
||||
[[ `$VIRTUAL_ENV/bin/python -m ipykernel -V &> /dev/null` ]] || $VIRTUAL_ENV/bin/python -m pip install ipykernel
|
||||
$VIRTUAL_ENV/bin/python -m ipykernel install --user --name=$(basename "${VIRTUAL_ENV//%\/.venv/}")
|
||||
fi
|
||||
fi
|
||||
@@ -0,0 +1,65 @@
|
||||
#autoload
|
||||
|
||||
bd () {
|
||||
(($#<1)) && {
|
||||
print -- "usage: $0 <name-of-any-parent-directory>"
|
||||
print -- " $0 <number-of-folders>"
|
||||
return 1
|
||||
} >&2
|
||||
# example:
|
||||
# $PWD == /home/arash/abc ==> $num_folders_we_are_in == 3
|
||||
local num_folders_we_are_in=${#${(ps:/:)${PWD}}}
|
||||
local dest="./"
|
||||
|
||||
# First try to find a folder with matching name (could potentially be a number)
|
||||
# Get parents (in reverse order)
|
||||
local parents
|
||||
local i
|
||||
for i in {$num_folders_we_are_in..2}
|
||||
do
|
||||
parents=($parents "$(echo $PWD | cut -d'/' -f$i)")
|
||||
done
|
||||
parents=($parents "/")
|
||||
# Build dest and 'cd' to it
|
||||
local parent
|
||||
foreach parent (${parents})
|
||||
do
|
||||
dest+="../"
|
||||
if [[ $1 == $parent ]]
|
||||
then
|
||||
cd $dest
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
# If the user provided an integer, go up as many times as asked
|
||||
dest="./"
|
||||
if [[ "$1" = <-> ]]
|
||||
then
|
||||
if [[ $1 -gt $num_folders_we_are_in ]]
|
||||
then
|
||||
print -- "bd: Error: Can not go up $1 times (not enough parent directories)"
|
||||
return 1
|
||||
fi
|
||||
for i in {1..$1}
|
||||
do
|
||||
dest+="../"
|
||||
done
|
||||
cd $dest
|
||||
return 0
|
||||
fi
|
||||
|
||||
# If the above methods fail
|
||||
print -- "bd: Error: No parent directory named '$1'"
|
||||
return 1
|
||||
}
|
||||
_bd () {
|
||||
# Get parents (in reverse order)
|
||||
local num_folders_we_are_in=${#${(ps:/:)${PWD}}}
|
||||
local i
|
||||
for i in {$num_folders_we_are_in..2}
|
||||
do
|
||||
reply=($reply "`echo $PWD | cut -d'/' -f$i`")
|
||||
done
|
||||
reply=($reply "/")
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
#autoload
|
||||
|
||||
biggest() {
|
||||
emulate -L zsh
|
||||
setopt pipe_fail
|
||||
|
||||
local count=20
|
||||
local pattern='*'
|
||||
|
||||
# Option parsing
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
-n|--number)
|
||||
count="$2"
|
||||
shift 2
|
||||
;;
|
||||
-p|--pattern)
|
||||
pattern="$2"
|
||||
shift 2
|
||||
;;
|
||||
-h|--help)
|
||||
cat <<'EOF'
|
||||
Usage: biggest [-n COUNT | --number COUNT] [-p PATTERN | --pattern PATTERN]
|
||||
|
||||
-n, --number Number of entries to show (default: 20)
|
||||
-p, --pattern Glob-style pattern to match names (default: *)
|
||||
-h, --help Show this help and exit
|
||||
|
||||
The command scans up to three directory levels below the current
|
||||
directory, includes hidden files and directories, and prints the
|
||||
largest files/directories sorted by size. Sizes are sorted using
|
||||
du -sk (numeric) and displayed using du -sh (human-readable).
|
||||
EOF
|
||||
return 0
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
break
|
||||
;;
|
||||
-*)
|
||||
print -u2 "biggest: unknown option: $1"
|
||||
return 1
|
||||
;;
|
||||
*)
|
||||
# Ignore unexpected positional args for now
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Validate count
|
||||
if ! [[ "$count" == <-> ]]; then
|
||||
print -u2 "biggest: COUNT must be a positive integer"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Core logic: depth 1–3, files and dirs, include hidden, suppress errors
|
||||
find . -mindepth 1 -maxdepth 3 -name "$pattern" -print0 2>/dev/null \
|
||||
| xargs -0 -n 100 du -sk 2>/dev/null \
|
||||
| sort -nr \
|
||||
| head -n "$count" \
|
||||
| cut -f2- \
|
||||
| tr '\n' '\0' \
|
||||
| xargs -0 -I{} du -sh "{}" 2>/dev/null \
|
||||
| awk '{
|
||||
size=$1
|
||||
$1=""
|
||||
sub(/^ /,"")
|
||||
# green size, blue path
|
||||
printf "\033[1;32m%-8s\033[0m \033[1;34m%s\033[0m\n", size, $0
|
||||
}'
|
||||
}
|
||||
Executable
+81
@@ -0,0 +1,81 @@
|
||||
# ===============================================================
|
||||
# call_file — Timed JSON logger for Zsh config execution
|
||||
# ===============================================================
|
||||
# Source this file early (e.g. in ~/.zshenv). It defines a function:
|
||||
# call_file /path/to/script.zsh [label]
|
||||
# Logs NDJSON lines to $outfile (default: ~/zshrc-log.json)
|
||||
|
||||
function call_file() {
|
||||
# No set -u here; be tolerant during early boot
|
||||
local filepath="$1"
|
||||
local label="${2:-}"
|
||||
local resolved_path exit_code=0 duration_ms start_time end_time LOGFILE json_entry
|
||||
|
||||
[[ -z "$filepath" ]] && return 0
|
||||
|
||||
LOGFILE="${outfile:-$HOME/zshrc-log.json}"
|
||||
: "${CALL_FILE_DEBUG:=0}"
|
||||
|
||||
# Resolve path (follow symlinks if present), fallback safely on macOS
|
||||
if [[ -L "$filepath" ]]; then
|
||||
if command -v readlink >/dev/null 2>&1 && readlink -f / >/dev/null 2>&1; then
|
||||
resolved_path="$(readlink -f "$filepath" 2>/dev/null || echo "$filepath")"
|
||||
elif command -v realpath >/dev/null 2>&1; then
|
||||
resolved_path="$(realpath "$filepath" 2>/dev/null || echo "$filepath")"
|
||||
else
|
||||
resolved_path="$filepath"
|
||||
fi
|
||||
else
|
||||
resolved_path="$filepath"
|
||||
fi
|
||||
|
||||
# Derive label if not provided: config.zsh -> parent dir name, else file stem
|
||||
if [[ -z "$label" ]]; then
|
||||
local fname="${resolved_path:t}"
|
||||
local dname="${resolved_path:h:t}"
|
||||
if [[ "$fname" == "config.zsh" ]]; then
|
||||
label="$dname"
|
||||
else
|
||||
label="${fname:r}"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Guard if file missing
|
||||
[[ ! -r "$resolved_path" ]] && {
|
||||
print -u2 "call_file: missing or unreadable: $resolved_path"
|
||||
return 1
|
||||
}
|
||||
|
||||
# Timestamps (μs precision). Fall back if EPOCHREALTIME is unavailable.
|
||||
start_time="${EPOCHREALTIME:-$(perl -MTime::HiRes=time -e 'printf "%.6f\n", time()')}"
|
||||
[[ "$CALL_FILE_DEBUG" != "0" ]] && print -- "▶️ Starting $resolved_path (label: $label)"
|
||||
|
||||
{
|
||||
# source quietly; the config can print if it wants—logs stay clean
|
||||
source "$resolved_path"
|
||||
} >/dev/null 2>&1 || exit_code=$?
|
||||
|
||||
end_time="${EPOCHREALTIME:-$(perl -MTime::HiRes=time -e 'printf "%.6f\n", time()')}"
|
||||
# Floating math via awk to avoid zsh int math pitfalls
|
||||
duration_ms=$(awk -v s="$start_time" -v e="$end_time" 'BEGIN {printf "%.5f", (e - s) * 1000}')
|
||||
|
||||
[[ "$CALL_FILE_DEBUG" != "0" ]] && print -- "⏱ Finished $resolved_path in ${duration_ms}ms (exit:${exit_code})"
|
||||
|
||||
# Ensure logfile dir exists
|
||||
mkdir -p -- "$(dirname -- "$LOGFILE")" 2>/dev/null
|
||||
|
||||
# NDJSON entry (numbers are real numbers via --argjson)
|
||||
json_entry=$(jq -nc \
|
||||
--arg file "$resolved_path" \
|
||||
--arg label "$label" \
|
||||
--argjson start "$(printf "%.5f" "$start_time")" \
|
||||
--argjson end "$(printf "%.5f" "$end_time")" \
|
||||
--argjson duration "$(printf "%.5f" "$duration_ms")" \
|
||||
--argjson code "$exit_code" \
|
||||
'{file:$file, label:$label, start:$start, end:$end, duration_ms:$duration, exit_code:$code}')
|
||||
|
||||
# Append (don’t fail if file doesn’t exist yet)
|
||||
if [[ -w "$LOGFILE" || ! -e "$LOGFILE" ]]; then
|
||||
print -- "$json_entry" >>"$LOGFILE"
|
||||
fi
|
||||
}
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env zsh
|
||||
NEWPATH=()
|
||||
DELPATH=()
|
||||
new_path() {
|
||||
for el in ${${(R)${(us/:/)PATH}:#* *}[@]}; do
|
||||
if [[ -d $el ]]; then
|
||||
NEWPATH+=$el
|
||||
else
|
||||
DELPATH+=$el
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
new_path
|
||||
# echo ${(F)DELPATH}
|
||||
echo ${(j/:/)NEWPATH}
|
||||
Executable
+159
@@ -0,0 +1,159 @@
|
||||
#autoload
|
||||
# compinit_doctor — inspect, audit, diff, and (optionally) rebuild zsh completion state
|
||||
# Usage: compinit_doctor [--status] [--audit] [--rebuild] [--snap FILE] [--diff FILE] [--dump PATH] [--json] [--help]
|
||||
|
||||
compinit_doctor() {
|
||||
emulate -L zsh
|
||||
setopt extended_glob
|
||||
zmodload -F zsh/datetime 2>/dev/null || true
|
||||
|
||||
# -------- defaults --------
|
||||
local dump="${ZSH_COMPDUMP:-${XDG_CACHE_HOME:-$HOME/.cache}/zcompdump}"
|
||||
local action=status json=0 snap_file="" diff_file=""
|
||||
|
||||
# -------- arg parse --------
|
||||
while (( $# > 0 )); do
|
||||
case "$1" in
|
||||
--help|-h) action=help;;
|
||||
--status|-s) action=status;;
|
||||
--audit|-a) action=audit;;
|
||||
--rebuild|-r) action=rebuild;;
|
||||
--snap|-S) shift; snap_file="${1:-}"; [[ -z $snap_file ]] && { print -ru2 "compinit_doctor: --snap requires a file"; return 2; }; action=snap;;
|
||||
--diff|-d) shift; diff_file="${1:-}"; [[ -z $diff_file ]] && { print -ru2 "compinit_doctor: --diff requires a file"; return 2; }; action=diff;;
|
||||
--dump=*|-D=*) dump="${1#*=}";;
|
||||
--dump|-D) shift; dump="${1:-$dump}";;
|
||||
--json|-j) json=1;;
|
||||
*) print -ru2 "compinit_doctor: unknown option: $1"; return 2;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
# -------- helpers --------
|
||||
__mtime() {
|
||||
[[ -e $1 ]] && stat -c %Y -- "$1" 2>/dev/null || return 1
|
||||
}
|
||||
__age_human() {
|
||||
local mt now delta
|
||||
mt="$(__mtime "$1")" || { print -r -- "—"; return 0; }
|
||||
now="${EPOCHSECONDS:-$(date +%s)}"
|
||||
delta=$(( now - mt )); (( delta < 0 )) && delta=0
|
||||
printf "%dd %02dh %02dm" $((delta/86400)) $(((delta%86400)/3600)) $(((delta%3600)/60))
|
||||
}
|
||||
__exists() { [[ -e $1 ]] && print yes || print no; }
|
||||
__count_comps() { (( ${+_comps} )) && print ${#_comps} || print 0; }
|
||||
|
||||
__print_status_text() {
|
||||
local dump_mtime dump_age compiled="${dump}.zwc"
|
||||
dump_mtime="$(__mtime "$dump" 2>/dev/null)" || dump_mtime="—"
|
||||
dump_age="$(__age_human "$dump")"
|
||||
|
||||
print -r -- "compinit status:"
|
||||
print -r -- " dump path : $dump"
|
||||
print -r -- " dump exists : $(__exists "$dump")"
|
||||
print -r -- " dump age : $dump_age"
|
||||
print -r -- " compiled exists : $(__exists "$compiled")"
|
||||
print -r -- " \$fpath entries : ${#fpath}"
|
||||
print -r -- " \$fpath missing : $(
|
||||
local -a miss d
|
||||
for d in $fpath; do [[ -d $d ]] || miss+=("$d"); done
|
||||
print ${#miss}
|
||||
)"
|
||||
print -r -- " completion funcs : $(__count_comps)"
|
||||
print -r -- " compinit present : $((($+functions[compinit] || $+commands[compinit])) && print "yes" || print "no")"
|
||||
}
|
||||
|
||||
__print_status_json() {
|
||||
local -a missing=(); local d
|
||||
for d in $fpath; do [[ -d $d ]] || missing+=("$d"); done
|
||||
local compinit_present=false
|
||||
if (( $+functions[compinit] || $+commands[compinit] )); then compinit_present=true; fi
|
||||
|
||||
printf '{"dump":"%s","dump_exists":%s,"dump_age":"%s","compiled_exists":%s,' \
|
||||
"$dump" "$([[ -e $dump ]] && print true || print false)" "$(__age_human "$dump")" "$([[ -e ${dump}.zwc ]] && print true || print false)"
|
||||
printf '"fpath_count":%d,"fpath_missing_count":%d,"completion_funcs":%d,"compinit_present":%s}\n' \
|
||||
"${#fpath}" "${#missing}" "$(__count_comps)" "$compinit_present"
|
||||
}
|
||||
|
||||
__do_audit() {
|
||||
if ! whence -w compaudit >/dev/null 2>&1; then
|
||||
print -ru2 "compinit_doctor: compaudit not available"; return 3
|
||||
fi
|
||||
local -a insecure
|
||||
insecure=(${(f)"$(compaudit 2>/dev/null)"})
|
||||
if (( ${#insecure} )); then
|
||||
print -r -- "Insecure completion dirs/files:"
|
||||
printf " %s\n" "${insecure[@]}"
|
||||
print -r -- "\nSuggested fix (review before running):"
|
||||
print -r -- " chmod -R go-w -- ${insecure:q}"
|
||||
else
|
||||
print -r -- "No insecure completion paths found (compaudit)."
|
||||
fi
|
||||
}
|
||||
|
||||
__do_rebuild() {
|
||||
local t0 t1 dt
|
||||
t0="${EPOCHREALTIME:-$(perl -MTime::HiRes=time -e 'printf \"%.6f\", time()')}"
|
||||
autoload -U compinit
|
||||
compinit -i -d "$dump" || { print -ru2 "compinit_doctor: compinit failed"; return 4; }
|
||||
{ zcompile "$dump" 2>/dev/null || true; } &
|
||||
t1="${EPOCHREALTIME:-$(perl -MTime::HiRes=time -e 'printf \"%.6f\", time()')}"
|
||||
dt=$(awk -v s="$t0" -v e="$t1" 'BEGIN{printf "%.3f",(e-s)*1000}')
|
||||
printf 'Rebuilt dump at: %s (compinit %.3fms)\n' "$dump" "$dt"
|
||||
}
|
||||
|
||||
__snap() {
|
||||
local file="$1"
|
||||
[[ -n $file ]] || { print -ru2 "compinit_doctor: snapshot file required"; return 2; }
|
||||
mkdir -p -- "${file:h}" 2>/dev/null
|
||||
{
|
||||
print "# compinit_doctor snapshot"
|
||||
print "# date: $(date +'%Y-%m-%d %H:%M:%S %z')"
|
||||
printf "%s\n" "${(o)fpath[@]}"
|
||||
} >| "$file"
|
||||
print -r -- "Snapshot written: $file"
|
||||
}
|
||||
|
||||
__diff() {
|
||||
local file="$1"
|
||||
[[ -r $file ]] || { print -ru2 "compinit_doctor: cannot read snapshot: $file"; return 2; }
|
||||
local -a snap cur added removed
|
||||
snap=(${(f)"$(<"$file")"})
|
||||
snap=(${snap:#\#*})
|
||||
cur=(${(o)fpath})
|
||||
local -Ua _S _C
|
||||
_S=("${snap[@]}"); _C=("${cur[@]}")
|
||||
local s c
|
||||
for s in "${_S[@]}"; do [[ -z ${_C[(r)$s]} ]] && removed+=("$s"); done
|
||||
for c in "${_C[@]}"; do [[ -z ${_S[(r)$c]} ]] && added+=("$c"); done
|
||||
print -r -- "fpath diff vs $file:"
|
||||
print -r -- " added (${#added}):"
|
||||
printf " + %s\n" "${added[@]}"
|
||||
print -r -- " removed(${#removed}):"
|
||||
printf " - %s\n" "${removed[@]}"
|
||||
}
|
||||
|
||||
# -------- dispatch --------
|
||||
case "$action" in
|
||||
help)
|
||||
cat <<'EOF'
|
||||
compinit_doctor — inspect, audit, diff, and rebuild zsh completion state
|
||||
|
||||
--status|-s Show current compinit/zcompdump status (default)
|
||||
--audit |-a Run compaudit and list insecure paths
|
||||
--rebuild|-r Force compinit -i -d <dump> and background zcompile
|
||||
--snap |-S FILE Snapshot current $fpath (sorted) to FILE
|
||||
--diff |-d FILE Diff current $fpath against FILE snapshot
|
||||
--dump |-D PATH Override zcompdump path (default: $XDG_CACHE_HOME/zcompdump)
|
||||
--json |-j Emit status as a single JSON object
|
||||
--help |-h Show this help
|
||||
EOF
|
||||
;;
|
||||
audit) __do_audit;;
|
||||
rebuild) __do_rebuild;;
|
||||
snap) __snap "$snap_file";;
|
||||
diff) __diff "$diff_file";;
|
||||
status)
|
||||
(( json )) && __print_status_json || __print_status_text
|
||||
;;
|
||||
esac
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
#autoload
|
||||
|
||||
# Helper: backup a file via a dummy backup script/command
|
||||
confe_backup_file() {
|
||||
emulate -L zsh
|
||||
|
||||
local file=${1:A}
|
||||
if [[ -z $file ]]; then
|
||||
print -u2 "confe: no file passed to confe_backup_file"
|
||||
return 1
|
||||
fi
|
||||
if [[ ! -e $file ]]; then
|
||||
print -u2 "confe: cannot backup, file does not exist: $file"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# You can override this with: CONFE_BACKUP_CMD=your-script
|
||||
local backup_cmd=${CONFE_BACKUP_CMD:-echo}
|
||||
|
||||
# Dummy backup – replace with your real backup script
|
||||
"$backup_cmd" "$file"
|
||||
}
|
||||
|
||||
# Helper: stage a file in its git repository (if there is one)
|
||||
confe_stage_file() {
|
||||
emulate -L zsh
|
||||
|
||||
local file=${1:A}
|
||||
if [[ -z $file ]]; then
|
||||
print -u2 "confe: no file passed to confe_stage_file"
|
||||
return 1
|
||||
fi
|
||||
if [[ ! -e $file ]]; then
|
||||
print -u2 "confe: cannot stage, file does not exist: $file"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local dir=${file:h}
|
||||
|
||||
if git -C "$dir" rev-parse --is-inside-work-tree &>/dev/null; then
|
||||
git -C "$dir" add "$file"
|
||||
else
|
||||
print -u2 "confe: $file is not inside a git repository"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
confe() {
|
||||
emulate -L zsh
|
||||
|
||||
# Main executable for editing – define here.
|
||||
# You can also override with CONFE_EDIT_CMD in your env.
|
||||
local edit_cmd=${CONFE_EDIT_CMD:-${EDITOR:-vim}}
|
||||
[[ -z $edit_cmd ]] && edit_cmd=nvim
|
||||
|
||||
local do_backup=false
|
||||
local do_staged=false
|
||||
local -a positional
|
||||
|
||||
# Option parsing: --backup/-b, --staged/-s
|
||||
while (( $# > 0 )); do
|
||||
case "$1" in
|
||||
--backup|-b)
|
||||
do_backup=true
|
||||
;;
|
||||
--staged|-s)
|
||||
do_staged=true
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
positional+=("$@")
|
||||
break
|
||||
;;
|
||||
--*)
|
||||
print -u2 "confe: unknown option: $1"
|
||||
return 1
|
||||
;;
|
||||
-*)
|
||||
print -u2 "confe: unknown short option: $1"
|
||||
return 1
|
||||
;;
|
||||
*)
|
||||
positional+=("$1")
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
set -- "${positional[@]}"
|
||||
|
||||
local topic=$1
|
||||
if [[ -z $topic ]]; then
|
||||
print -u2 "usage: confe [--backup|-b] [--staged|-s] (alias|keybindings|options|path|packages|ssh|brewfile)"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Associative array: topic → file path
|
||||
local -A CONFE_FILES=(
|
||||
alias "$ZDOTDIR/alias.zsh"
|
||||
keybindings "$ZDOTDIR/keybindings.zsh"
|
||||
options "$ZDOTDIR/options.zsh"
|
||||
path "$ZDOTDIR/path.zsh"
|
||||
packages "$DOTFILES/antidote/zsh_plugins.txt"
|
||||
ssh "$HOME/.ssh/config"
|
||||
brewfile "$DOTFILES/00-homebrew/Brewfile"
|
||||
)
|
||||
|
||||
local file=${CONFE_FILES[$topic]}
|
||||
|
||||
if [[ -z $file ]]; then
|
||||
print -u2 "confe: unknown topic: $topic"
|
||||
print -u2 "valid topics: ${(j:, :)${(k)CONFE_FILES}}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Run backup first if requested
|
||||
if $do_backup; then
|
||||
confe_backup_file "$file" || return $?
|
||||
fi
|
||||
|
||||
# Main dummy command – you replace by setting edit_cmd / CONFE_EDIT_CMD
|
||||
eval "$edit_cmd" $file(:P) || return $?
|
||||
if [[ "${file}(:e)" == "zsh" ]]; then
|
||||
source $file(:P)
|
||||
fi
|
||||
|
||||
# Stage changes if requested
|
||||
if $do_staged; then
|
||||
confe_stage_file "$file" || return $?
|
||||
fi
|
||||
}
|
||||
|
||||
confe ${1:-ssh}
|
||||
@@ -0,0 +1,62 @@
|
||||
#autoload
|
||||
#
|
||||
copy_hosts() {
|
||||
local -a cp_hosts_default=( infra-dns-1 swarm-mgr-1 swarm-mgr-2 swarm-mgr-3 proxmox-01 )
|
||||
local -a cp_hosts_new=()
|
||||
local -a cp_hosts=()
|
||||
local -a cp_sources=()
|
||||
local saw_hosts=0
|
||||
|
||||
while (( $# > 0 )); do
|
||||
case "$1" in
|
||||
-h|--hosts)
|
||||
saw_hosts=1
|
||||
shift
|
||||
|
||||
# Collect host names until:
|
||||
# - we hit "--"
|
||||
# - or only one argument remains (treat that as a source)
|
||||
while (( $# > 1 )) && [[ "$1" != "--" ]]; do
|
||||
cp_hosts_new+=("$1")
|
||||
shift
|
||||
done
|
||||
|
||||
# Keep only hosts that exist in cp_hosts_default
|
||||
cp_hosts=( ${cp_hosts_default:*cp_hosts_new} )
|
||||
|
||||
# Skip the separator if present
|
||||
if (( $# > 0 )) && [[ "$1" == "--" ]]; then
|
||||
shift
|
||||
fi
|
||||
;;
|
||||
|
||||
--)
|
||||
shift
|
||||
cp_sources+=( "$@" )
|
||||
break
|
||||
;;
|
||||
|
||||
*)
|
||||
cp_sources+=("$1")
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# No -h/--hosts provided: use defaults
|
||||
if (( ! saw_hosts )); then
|
||||
cp_hosts=( "${cp_hosts_default[@]}" )
|
||||
fi
|
||||
|
||||
# Nothing valid matched from -h/--hosts: fall back to defaults
|
||||
if (( saw_hosts )) && (( ${#cp_hosts[@]} == 0 )); then
|
||||
cp_hosts=( "${cp_hosts_default[@]}" )
|
||||
fi
|
||||
|
||||
for dotdir in "${cp_sources[@]}"; do
|
||||
[[ -e "${DOTFILES}/${dotdir}" ]] || continue
|
||||
for dothost in "${cp_hosts[@]}"; do
|
||||
dotpush "$dothost" "$dotdir"
|
||||
done
|
||||
done
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#autoload
|
||||
dot () {
|
||||
_dotfiles="${DOTFILES:-$HOME/.dotfiles}"
|
||||
if [ $# -eq 1 ]; then
|
||||
if [[ -d "${_dotfiles}/$1" ]]; then
|
||||
cd "${_dotfiles}/$1"
|
||||
else
|
||||
echo "no dir $1 in ${_dotfiles}"
|
||||
fi
|
||||
else
|
||||
cd "${_dotfiles}"
|
||||
fi
|
||||
if command -v eza >/dev/null 2>&1; then
|
||||
eza --grid --git-ignore --all --header --grid --no-permissions --no-filesize --no-time --no-user --icons --git --hyperlink
|
||||
elif command -v colorls >/dev/null 2>&1; then
|
||||
colorls -A --sd --hyperlink --gs
|
||||
else
|
||||
ls -a --color=auto
|
||||
fi
|
||||
}
|
||||
Executable
+128
@@ -0,0 +1,128 @@
|
||||
#!/usr/bin/env zsh
|
||||
# ===============================================================
|
||||
# dotfiles_doctor — Zsh Config Health & Timeline Analyzer
|
||||
# ===============================================================
|
||||
|
||||
# Be interactive-safe: never kill the session on errors here
|
||||
unsetopt errexit 2>/dev/null || true
|
||||
unsetopt nounset 2>/dev/null || true
|
||||
unsetopt pipefail 2>/dev/null || true
|
||||
setopt NO_NOMATCH
|
||||
|
||||
LOGFILE="$HOME/zshrc-log.json"
|
||||
SHOW_TIMELINE=0
|
||||
SLOW_THRESHOLD=${SLOW_THRESHOLD:-200}
|
||||
WARN_THRESHOLD=${WARN_THRESHOLD:-500}
|
||||
|
||||
# --- Argument parsing (flags only; NDJSON log stays default unless overridden) ---
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--timeline) SHOW_TIMELINE=1 ;;
|
||||
--logfile=*) LOGFILE="${arg#*=}" ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# --- Pre-flight checks (non-fatal for interactive) ---
|
||||
if ! command -v jq >/dev/null 2>&1; then
|
||||
print -P "%F{red}❌ jq is required (brew install jq)%f"
|
||||
return 1 2>/dev/null || exit 1
|
||||
fi
|
||||
if [[ ! -f "$LOGFILE" ]]; then
|
||||
print -P "%F{red}❌ No log file found:%f $LOGFILE"
|
||||
return 1 2>/dev/null || exit 1
|
||||
fi
|
||||
|
||||
print
|
||||
print "🩺 Dotfiles Doctor — Startup Diagnostic"
|
||||
print "📄 Log: $LOGFILE"
|
||||
print "⚙️ Slow threshold: ${SLOW_THRESHOLD}ms | Warn threshold: ${WARN_THRESHOLD}ms"
|
||||
print "---------------------------------------------------------------"
|
||||
|
||||
# ---- Individual file timings (slurp NDJSON -> array; then iterate) ----
|
||||
jq -sr '.[] | [.label, (.duration_ms // 0), (.exit_code // 0), .file] | @tsv' "$LOGFILE" |
|
||||
while IFS=$'\t' read -r label duration exit_code file; do
|
||||
color="" reset=$'\033[0m' emoji="✅"
|
||||
if (( exit_code != 0 )); then color=$'\033[31m'; emoji="💥"
|
||||
elif (( ${duration%.*} > WARN_THRESHOLD )); then color=$'\033[31m'; emoji="🔥"
|
||||
elif (( ${duration%.*} > SLOW_THRESHOLD )); then color=$'\033[33m'; emoji="⚠️ "
|
||||
else color=$'\033[32m'; fi
|
||||
printf "%b%-22s %8.3fms (exit:%3d) %s%b\n" \
|
||||
"$color$emoji " "$label" "$duration" "$exit_code" "$file" "$reset"
|
||||
done
|
||||
|
||||
print "---------------------------------------------------------------"
|
||||
|
||||
# ---- Aggregate summary (right-justified, 3 decimals) ----
|
||||
echo "📊 Aggregate timings:"
|
||||
jq -sr '
|
||||
group_by(.label)
|
||||
| map({
|
||||
label: .[0].label,
|
||||
count: length,
|
||||
total: (map(.duration_ms // 0) | add),
|
||||
avg: ((map(.duration_ms // 0) | add) / length)
|
||||
})
|
||||
| sort_by(.label)
|
||||
| .[]
|
||||
| [.label, (.count|tostring), (.total|tostring), (.avg|tostring)]
|
||||
| @tsv
|
||||
' "$LOGFILE" |
|
||||
awk -F '\t' '
|
||||
BEGIN {
|
||||
printf "%-26s %7s %12s %10s\n", "label", "count", "total_ms", "avg_ms"
|
||||
printf "%-26s %7s %12s %10s\n", "-----", "-----", "--------", "------"
|
||||
}
|
||||
{
|
||||
label=$1; count=$2+0; total=$3+0; avg=$4+0
|
||||
printf "%-26s %7d %12.3f %10.3f\n", label, count, total, avg
|
||||
}'
|
||||
|
||||
# ---- Totals ----
|
||||
sum_total=$(jq -sr '[.[].duration_ms // 0] | add' "$LOGFILE")
|
||||
# Session elapsed = (max end - min start) * 1000 (if present)
|
||||
session_total_ms=$(jq -sr '
|
||||
( [.[].start] | map(select(. != null)) ) as $s
|
||||
| ( [.[].end] | map(select(. != null)) ) as $e
|
||||
| if ($s|length)>0 and ($e|length)>0
|
||||
then (( ($e|max) - ($s|min) ) * 1000)
|
||||
else 0
|
||||
end
|
||||
' "$LOGFILE")
|
||||
|
||||
fails=$(jq -sr '[.[].exit_code // 0] | map(select(. != 0)) | length' "$LOGFILE")
|
||||
slows=$(jq -sr "[.[].duration_ms // 0] | map(select(. > $SLOW_THRESHOLD)) | length" "$LOGFILE")
|
||||
|
||||
printf "\n🕒 Total (sum of durations): %.5fms\n" "$sum_total"
|
||||
printf "🕒 Session elapsed (first→last): %.5fms\n" "$session_total_ms"
|
||||
print "💀 Failed modules: $fails"
|
||||
print "🐢 Slow modules: $slows"
|
||||
print
|
||||
|
||||
if (( fails > 0 )); then
|
||||
print "❗ One or more modules failed to load. Check 💥 entries."
|
||||
elif (( slows > 0 )); then
|
||||
print "⚠️ Some modules exceeded ${SLOW_THRESHOLD}ms."
|
||||
else
|
||||
print "✅ All modules healthy and fast."
|
||||
fi
|
||||
|
||||
# ---- Timeline (optional; format times in shell, not jq) ----
|
||||
if (( SHOW_TIMELINE )); then
|
||||
print
|
||||
print "🕰️ Load Timeline (start→end, μs precision)"
|
||||
print "---------------------------------------------------------------"
|
||||
|
||||
jq -sr '.[] | select(.start != null and .end != null)
|
||||
| [.label, (.start|tostring), (.end|tostring), (.duration_ms // 0), (.exit_code // 0), .file]
|
||||
| @tsv' "$LOGFILE" |
|
||||
while IFS=$'\t' read -r label start end duration exit_code file; do
|
||||
# hh:mm:ss.fffff formatting in shell
|
||||
s_sec="${start%.*}"; s_frac="${start#*.}"; s_frac="${s_frac%%[^0-9]*}"; s_frac="${s_frac:0:5}"
|
||||
e_sec="${end%.*}" ; e_frac="${end#*.}" ; e_frac="${e_frac%%[^0-9]*}" ; e_frac="${e_frac:0:5}"
|
||||
s_hms="$(date -r "$s_sec" +%H:%M:%S 2>/dev/null).$(printf "%05d" ${s_frac:-0})"
|
||||
e_hms="$(date -r "$e_sec" +%H:%M:%S 2>/dev/null).$(printf "%05d" ${e_frac:-0})"
|
||||
printf "%-22s %s → %s %8.3fms (exit:%3d) %s\n" \
|
||||
"$label" "$s_hms" "$e_hms" "$duration" "$exit_code" "$file"
|
||||
done
|
||||
print "---------------------------------------------------------------"
|
||||
fi
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
#autoload
|
||||
|
||||
dotpush() {
|
||||
local host="$1"
|
||||
rsync -azc \
|
||||
--update \
|
||||
--backup --suffix='.bak' \
|
||||
--filter=':- .gitignore' \
|
||||
--exclude='.git/' \
|
||||
-e ssh \
|
||||
"$DOTFILES/$2" \
|
||||
"$host:~/.dotfiles/"
|
||||
}
|
||||
|
||||
Executable
+30
@@ -0,0 +1,30 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Usage: extract <file>
|
||||
# Description: extracts archived files / mounts disk images
|
||||
# Note: .dmg/hdiutil is macOS-specific.
|
||||
#
|
||||
# credit: http://nparikh.org/notes/zshrc.txt
|
||||
extract () {
|
||||
if [ -f $1 ]; then
|
||||
case $1 in
|
||||
*.tar.bz2) tar -jxvf $1 || echo $1 ;;
|
||||
*.tar.gz) tar -zxvf $1 ;;
|
||||
*.bz2) bunzip2 $1 ;;
|
||||
*.dmg) hdiutil mount $1 ;;
|
||||
*.gz) gunzip $1 ;;
|
||||
*.tar) tar -xvf $1 ;;
|
||||
*.tbz2) tar -jxvf $1 ;;
|
||||
*.tgz) tar -zxvf $1 ;;
|
||||
*.zip) unzip $1 ;;
|
||||
*.ZIP) unzip $1 ;;
|
||||
*.pax) cat $1 | pax -r ;;
|
||||
*.pax.Z) uncompress $1 --stdout | pax -r ;;
|
||||
*.rar) unrar x $1 ;;
|
||||
*.Z) uncompress $1 ;;
|
||||
*) echo "'$1' cannot be extracted/mounted via extract()" ;;
|
||||
esac
|
||||
else
|
||||
echo "'$1' is not a valid file"
|
||||
fi
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
#autoload
|
||||
|
||||
find_dupes() {
|
||||
local maxdepth=3 regex='.*' ignore_case=false
|
||||
local tmpfile grep_flags="-E"
|
||||
|
||||
# ----------------------------
|
||||
# Parse args (all long opts must start with --)
|
||||
# ----------------------------
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--maxdepth|-d)
|
||||
maxdepth="$2"
|
||||
shift 2
|
||||
;;
|
||||
--regex|-r)
|
||||
regex="$2"
|
||||
shift 2
|
||||
;;
|
||||
--ignore-case|-i)
|
||||
ignore_case=true
|
||||
shift
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
break
|
||||
;;
|
||||
*)
|
||||
echo "find_dupes: unknown option '$1'" >&2
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# grep flags
|
||||
$ignore_case && grep_flags="$grep_flags -i"
|
||||
|
||||
tmpfile=$(mktemp /tmp/find_dupes.XXXXXX)
|
||||
|
||||
# ----------------------------
|
||||
# Scan files
|
||||
# ----------------------------
|
||||
find . -type f -maxdepth "$maxdepth" ! -path '*/.git/*' \
|
||||
\( -name "*.zsh" -o -name "*.sh" -o -name "*.zlogin" -o -name "*.symlink" -o ! -name "*.*" \) \
|
||||
-print0 | while IFS= read -r -d '' file; do
|
||||
|
||||
grep $grep_flags "$regex" "$file" 2>/dev/null | \
|
||||
awk '
|
||||
{
|
||||
gsub(/\r/, "", $0)
|
||||
gsub(/\302\240/, "", $0)
|
||||
line = $0
|
||||
}
|
||||
|
||||
/^[[:space:]]*#/ { next }
|
||||
|
||||
{
|
||||
sub(/^[[:space:]]+/, "", line)
|
||||
sub(/[[:space:]]+$/, "", line)
|
||||
|
||||
if (length(line) == 0) next
|
||||
if (length(line) < 5) next
|
||||
|
||||
print line "\t" FILENAME
|
||||
}
|
||||
' FILENAME="$file" >> "$tmpfile"
|
||||
done
|
||||
|
||||
# ----------------------------
|
||||
# Show duplicates
|
||||
# ----------------------------
|
||||
sort "$tmpfile" | awk -F'\t' '
|
||||
{
|
||||
line=$1; file=$2
|
||||
count[line]++
|
||||
files[line]=files[line] file "\n"
|
||||
}
|
||||
END {
|
||||
for (l in count)
|
||||
if (count[l] > 1) {
|
||||
print "==== Duplicate line: \"" l "\" ===="
|
||||
printf "%s", files[l]
|
||||
print ""
|
||||
}
|
||||
}
|
||||
'
|
||||
|
||||
rm -f "$tmpfile"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/zsh
|
||||
function echo_exists() {
|
||||
if [[ -e "${1:r}.py" ]]; then
|
||||
echo "${1:r}.py"
|
||||
# cat "${1:r}.py"
|
||||
elif [[ -e "${1:h}" ]]; then
|
||||
echo "${1:h}"
|
||||
else
|
||||
echo "${1} - no"
|
||||
fi
|
||||
}
|
||||
|
||||
typeset -a SEARCH_DIR=("${(@f)"$(<$DOTFILES/bin/jupconf.txt)"}")
|
||||
for _dir in "${SEARCH_DIR[@]}"; do
|
||||
echo_exists $_dir
|
||||
done
|
||||
|
||||
|
||||
|
||||
Executable
+58
@@ -0,0 +1,58 @@
|
||||
#!/usr/local/bin/zsh
|
||||
|
||||
function prefix() { PYENV_VERSION=3.9.5 pyenv exec "$@"; }
|
||||
function suffix_grep() { prefix "$@" | grep ${JUP_PORT:-9888}; }
|
||||
function suffix_null() { $@ >/dev/null 2>&1; }
|
||||
|
||||
function jupyter_start() {
|
||||
prefix nohup jupyter lab --no-browser --ServerApp.disable_check_xsrf=True --port ${JUP_PORT:-9888} -y >$HOME/jup.log 2>&1 &
|
||||
export JUP_PID=$!
|
||||
}
|
||||
|
||||
function jupyter_kill() {
|
||||
# prefix jupyter server stop ${JUP_PORT:-9888} >>$HOME/jup.log 2>&1
|
||||
suffix_null jupyter server stop ${JUP_PORT:-9888}
|
||||
unset JUP_PID
|
||||
}
|
||||
|
||||
function jupyter_help() {
|
||||
printf "Usage: jupyter_run [-h, --help] [--stop] [-s, --show] [-r, --restart]\n"
|
||||
}
|
||||
|
||||
function jupyter_run() {
|
||||
typeset -i num_arg
|
||||
num_arg=$#
|
||||
if [[ $num_arg == '0' ]]; then
|
||||
suffix_null suffix_grep jupyter server list || jupyter_start
|
||||
return 0 2>/dev/null
|
||||
fi
|
||||
while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do
|
||||
case $1 in
|
||||
-r | --restart)
|
||||
jupyter_kill
|
||||
jupyter_start
|
||||
return 0 2>/dev/null
|
||||
;;
|
||||
--stop)
|
||||
jupyter_kill
|
||||
return 0 2>/dev/null
|
||||
;;
|
||||
-s | --show)
|
||||
suffix_grep jupyter server list
|
||||
return 0 2>/dev/null
|
||||
;;
|
||||
-h | --help)
|
||||
jupyter_help
|
||||
return 0 2>/dev/null
|
||||
;;
|
||||
*)
|
||||
jupyter_help
|
||||
return 1 2>/dev/null
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
if [[ "$1" == '--' ]]; then shift; fi
|
||||
}
|
||||
|
||||
jupyter_run
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env zsh
|
||||
set -euo pipefail
|
||||
|
||||
SESS_DIR="$HOME/.config/kitty/sessions"
|
||||
|
||||
launch() {
|
||||
nohup kitty "$@" >/dev/null 2>&1 &
|
||||
disown
|
||||
}
|
||||
|
||||
if [[ -n "${1:-$DCS_PROJ_NAME}" ]]; then
|
||||
launch --session "${SESS_DIR}/${1:-$DCS_PROJ_NAME}.session"
|
||||
fi
|
||||
|
||||
cwd="$(pwd -P)"
|
||||
#
|
||||
#if [[ "$cwd" == "$HOME/dev/dcsctl"* ]]; then
|
||||
# launch --session "${SESS_DIR}/dcsctl.session"
|
||||
#elif [[ "$cwd" == "$HOME/PAN_Macbook/cycling-climbs"* ]]; then
|
||||
# launch --session "${SESS_DIR}/cycling.session"
|
||||
#else
|
||||
# launch --directory "$cwd"
|
||||
#fi
|
||||
|
||||
|
||||
Executable
+56
@@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env zsh
|
||||
# ===============================================================
|
||||
# log_parser.zsh — Pretty-print call_file JSON logs (aligned + exit codes)
|
||||
# ===============================================================
|
||||
|
||||
LOGFILE="${1:-$HOME/zshrc-log.json}"
|
||||
|
||||
if [[ ! -r "$LOGFILE" ]]; then
|
||||
echo "❌ Log file not found: $LOGFILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Parsed call_file log:"
|
||||
|
||||
# Arrays to hold parsed data
|
||||
labels=()
|
||||
durations=()
|
||||
exit_codes=()
|
||||
files=()
|
||||
|
||||
# Parse the JSON lines
|
||||
while IFS= read -r line; do
|
||||
label=$(echo "$line" | jq -r '.label // empty' 2>/dev/null)
|
||||
duration=$(echo "$line" | jq -r '.duration_ms // empty' 2>/dev/null)
|
||||
exit_code=$(echo "$line" | jq -r '.exit_code // empty' 2>/dev/null)
|
||||
file=$(echo "$line" | jq -r '.file // empty' 2>/dev/null)
|
||||
|
||||
[[ -z "$label" || -z "$file" ]] && continue
|
||||
|
||||
labels+=("$label")
|
||||
durations+=("${duration:-0}")
|
||||
exit_codes+=("${exit_code:-0}")
|
||||
files+=("$file")
|
||||
done < <(grep -E '"label"' "$LOGFILE")
|
||||
|
||||
# Determine max column widths for alignment
|
||||
max_label=0
|
||||
max_duration=0
|
||||
max_exit=0
|
||||
for label in "${labels[@]}"; do
|
||||
(( ${#label} > max_label )) && max_label=${#label}
|
||||
done
|
||||
for dur in "${durations[@]}"; do
|
||||
(( ${#dur} > max_duration )) && max_duration=${#dur}
|
||||
done
|
||||
for code in "${exit_codes[@]}"; do
|
||||
(( ${#code} > max_exit )) && max_exit=${#code}
|
||||
done
|
||||
|
||||
# Build sorted, aligned output
|
||||
{
|
||||
for i in {1..${#labels[@]}}; do
|
||||
printf "%-${max_label}s %${max_duration}sms %${max_exit}s %s\n" \
|
||||
"${labels[i-1]}" "${durations[i-1]}" "${exit_codes[i-1]}" "${files[i-1]}"
|
||||
done
|
||||
} | sort -k2,2n
|
||||
@@ -0,0 +1,9 @@
|
||||
function make_reqs() {
|
||||
mods=("${(@f)$(awk '/import/ { print $2 }' *.(py|ipynb) | sed -E 's:[\\\.\"].*::g;s~_~-~g' | sort --unique )}")
|
||||
pip freeze | grep -E "$(export IFS="|"; echo "${mods[*]}")"
|
||||
for mod in ${mods[*]}; do
|
||||
echo $mod
|
||||
echo `pip freeze | grep $mod`
|
||||
done
|
||||
unset mods
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
if [[ -w $HOME/PAN ]]; then
|
||||
hdiutil attach -mountpoint $HOME/PAN $HOME/Library/Mobile\ Documents/com\~apple\~CloudDocs/PAN.sparsebundle
|
||||
fi
|
||||
@@ -0,0 +1,19 @@
|
||||
#autoload
|
||||
|
||||
move_bak() {
|
||||
emulate -L zsh
|
||||
[[ -n $DEBUG_ZSH ]] && {
|
||||
export PS4='+%N:%i> '
|
||||
set -x
|
||||
}
|
||||
local _files
|
||||
typeset -a bakfiles=($HOME/.dotfiles/**/*.bak(DN))
|
||||
[[ ${#bakfiles} -gt 0 ]] || return 0
|
||||
for _files in "${(@u)bakfiles:h}"; do
|
||||
[[ -d ${_files//dotfiles/dotfiles-bak} ]] || eval "mkdir -p ${_files//dotfiles/dotfiles-bak}"
|
||||
done
|
||||
for _files in "${(@)bakfiles}"; do
|
||||
eval "mv ${(A)_files} ${_files//dotfiles/dotfiles-bak}"
|
||||
done
|
||||
unset bakfiles
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#/bin/zsh
|
||||
mvo () {
|
||||
for file in $@
|
||||
do
|
||||
if [[ ${file##*.} == "zsh" ]]; then
|
||||
mv "$file" "${file%%.*}.old"
|
||||
elif [[ ${1##*.} == "old" ]]; then
|
||||
mv "$file" "${file%%.*}.zsh"
|
||||
fi
|
||||
done
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#autoload
|
||||
neo_open() {
|
||||
if [[ -z $SSH_CONNECTION ]]; then
|
||||
local _nport=127.0.0.1:7777
|
||||
local _nfile="${1:A}"
|
||||
else
|
||||
local _nport=127.0.0.1:7778
|
||||
local _nfile="scp://$(hostname)//${1:A}"
|
||||
fi
|
||||
cmd_args=( "nvim" "--server" "${_nport}" "--remote" "${_nfile}")
|
||||
eval $cmd_args[@]
|
||||
if kitty @ ls -m "env:PANEL" >/dev/null 2>&1; then
|
||||
kitten @ --to ${KITTY_LISTEN_ON} resize-os-window --match env:PANEL --action=toggle-visibility
|
||||
fi
|
||||
}
|
||||
Executable
+32
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env zsh
|
||||
# nvim-open — open a file (with optional line) in the session's nvim server
|
||||
#
|
||||
# Usage:
|
||||
# nvim-open <path> [line]
|
||||
#
|
||||
# The nvim server is identified by $NVIM_SERVER, which is set per-session:
|
||||
# - Local: 127.0.0.1:7777 (default in nvim/env.zsh)
|
||||
# - nasng: 127.0.0.1:27777 (injected by ssh.conf)
|
||||
# - mining: 127.0.0.1:17777
|
||||
# - mininv: 127.0.0.1:37777
|
||||
#
|
||||
# Called from kitty hints:
|
||||
# map ctrl+shift+p>n kitten hints --type=linenum --linenum-action=overlay \
|
||||
# zsh -lic 'nvim-open {path} {line}'
|
||||
#
|
||||
# Called from nvim_panel.py for hyperlink-click-to-panel flow.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
NVIM_BIN="${NVIM_BIN:-/opt/homebrew/bin/nvim}"
|
||||
SERVER="${NVIM_SERVER:-127.0.0.1:7777}"
|
||||
FILE="${1:?nvim-open: file argument required}"
|
||||
LINE="${2:-}"
|
||||
|
||||
# Open file in a new tab in the running nvim instance
|
||||
"$NVIM_BIN" --server "$SERVER" --remote-tab "$(realpath "$FILE")"
|
||||
|
||||
# Jump to line if provided
|
||||
if [[ -n "$LINE" && "$LINE" =~ ^[0-9]+$ ]]; then
|
||||
"$NVIM_BIN" --server "$SERVER" --remote-send "<C-\\><C-n>:${LINE}<CR>"
|
||||
fi
|
||||
@@ -0,0 +1,6 @@
|
||||
#autoload
|
||||
o_panel(){
|
||||
local _fi
|
||||
_fi=$(realpath "$1")
|
||||
$HOME/.config/kitty/nvim_panel "${_fi}"
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
#autoload
|
||||
o_vim() { nvim --server 127.0.0.1:7777 --remote "${1:A}"; }
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/zsh
|
||||
# parent_find () {
|
||||
# # [[ -a ~/.localrc ]] && source ~/.localrc
|
||||
# topic=$(basename `${READLINK_DIR:="/bin"}/readlink -f ${1%/*}`)
|
||||
# }
|
||||
Executable
+20
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/zsh
|
||||
# while read -d ':' p; do
|
||||
# [[ -d $p ]] || NEW_PATH=$NEW_PATH"$p"
|
||||
# done <<< "$PATH:"
|
||||
# [[ $VIRTUAL_ENV != "*virtualenvs*" ]] &&
|
||||
|
||||
path_fix() {
|
||||
paths=($(tr ':' '\n' <<<"$PATH"))
|
||||
for p in "${paths[@]}"; do
|
||||
if [[ $VIRTUAL_ENV ]]; then
|
||||
continue
|
||||
fi
|
||||
[[ -d $p ]] && NEW_PATH="${NEW_PATH}${DELIM}${p}"
|
||||
DELIM=":"
|
||||
done
|
||||
# export OLDPATH=$PATH
|
||||
# export PATH=$NEW_PATH
|
||||
tr ':' '\n' <<<"$NEW_PATH"
|
||||
unset NEW_PATH
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/zsh
|
||||
# while read -d ':' p; do
|
||||
# [[ -d $p ]] || NEW_PATH=$NEW_PATH"$p"
|
||||
# done <<< "$PATH:"
|
||||
# [[ $VIRTUAL_ENV != "*virtualenvs*" ]] &&
|
||||
|
||||
path_fix () {
|
||||
paths=(`tr ':' '\n' <<< "$PATH"`)
|
||||
for p in "${paths[@]}" ; do
|
||||
if [[ $VIRTUAL_ENV =~ "virtualenvs"]] && [[ $p =~ "pyenv" ]]; then
|
||||
echo $p
|
||||
[[ -d $p ]] && NEW_PATH="${NEW_PATH}${DELIM}${p}"
|
||||
fi
|
||||
[[ -d $p ]] && NEW_PATH="${NEW_PATH}${DELIM}${p}"
|
||||
DELIM=":"
|
||||
done
|
||||
export OLDPATH=$PATH
|
||||
export PATH=$NEW_PATH
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
#autoload
|
||||
pdir() {
|
||||
local proj
|
||||
proj="${PROJECT:-$@}"
|
||||
[[ -z "$proj" ]] && { print -u2 "usage: pdir <project>"; return 2; }
|
||||
cd -- "$(dcsctl dir ${(As./.)proj})" || return
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
function ppgrep() { pgrep "$@" | xargs ps -fp 2> /dev/null; }
|
||||
@@ -0,0 +1,9 @@
|
||||
#/bin/zsh
|
||||
for file in $@
|
||||
do
|
||||
if [[ ${file##*.} == "sh" ]]; then
|
||||
mv "$file" "${file%%.*}"
|
||||
elif [[ ${1##*.} == "old" ]]; then
|
||||
mv "$file" "${file%%.*}.zsh"
|
||||
fi
|
||||
done
|
||||
@@ -0,0 +1,18 @@
|
||||
#!/usr/local/bin/zsh
|
||||
setopt extended_glob
|
||||
setopt null_glob
|
||||
setopt rematch_pcre
|
||||
|
||||
echo $1
|
||||
echo $2
|
||||
echo $3
|
||||
|
||||
if [[ -d $1 ]]; then
|
||||
echo ${1}"/**/*"${2}
|
||||
search_files=($1/**/*$2)
|
||||
fi
|
||||
# load the path files
|
||||
for file in $search_files
|
||||
do
|
||||
cat ${file} | grep $3
|
||||
done
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Sets macOS defaults by running $ZSH/macos/set-defaults.sh.
|
||||
|
||||
exec $ZSH/macos/set-defaults.sh
|
||||
Reference in New Issue
Block a user