update
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo "Usage: $0 -c COMMENT_SYMBOL [-e EXCLUDE_PATTERN]... TARGET"
|
echo "Usage: $(basename "$0") -c COMMENT_SYMBOL [-e EXCLUDE_PATTERN]... TARGET"
|
||||||
echo " -c Comment symbol (e.g., '#' or '//')"
|
echo " -c Comment symbol (e.g., '#' or '//')"
|
||||||
echo " -e Exclude pattern (can be specified multiple times)"
|
echo " -e Exclude pattern (can be specified multiple times)"
|
||||||
echo " TARGET File or directory to process"
|
echo " TARGET File or directory to process"
|
||||||
@@ -29,21 +29,10 @@ shift $((OPTIND - 1))
|
|||||||
target="$(realpath "$1")"
|
target="$(realpath "$1")"
|
||||||
base_dir="$(pwd)"
|
base_dir="$(pwd)"
|
||||||
|
|
||||||
should_exclude() {
|
|
||||||
local path="$1"
|
|
||||||
for pattern in "${excludes[@]}"; do
|
|
||||||
if [[ "$path" == *"$pattern"* ]]; then
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
process_file() {
|
process_file() {
|
||||||
local file="$1"
|
local file="$1"
|
||||||
local rel_path="${file#"$base_dir"/}"
|
# shellcheck disable=SC2295
|
||||||
|
local rel_path="${file#$base_dir/}"
|
||||||
should_exclude "$rel_path" && return
|
|
||||||
|
|
||||||
local path_comment="$comment_sym path: $rel_path"
|
local path_comment="$comment_sym path: $rel_path"
|
||||||
|
|
||||||
@@ -52,22 +41,37 @@ process_file() {
|
|||||||
IFS= read -r line1 <"$file" 2>/dev/null || line1=""
|
IFS= read -r line1 <"$file" 2>/dev/null || line1=""
|
||||||
IFS= read -r line2 < <(tail -n +2 "$file") 2>/dev/null || line2=""
|
IFS= read -r line2 < <(tail -n +2 "$file") 2>/dev/null || line2=""
|
||||||
|
|
||||||
# Check if path comment exists in first or second line
|
# Handle shebang case
|
||||||
[[ "$line1" == *"path: "* ]] && return
|
|
||||||
[[ "$line2" == *"path: "* ]] && return
|
|
||||||
|
|
||||||
# Insert after shebang if present, otherwise at top
|
|
||||||
if [[ "$line1" =~ ^#! ]]; then
|
if [[ "$line1" =~ ^#! ]]; then
|
||||||
{
|
if [[ "$line2" == *"path: "* ]]; then
|
||||||
echo "$line1"
|
# Replace existing path comment on line 2
|
||||||
echo "$path_comment"
|
{
|
||||||
tail -n +2 "$file"
|
echo "$line1"
|
||||||
} >"$file.tmp"
|
echo "$path_comment"
|
||||||
|
tail -n +3 "$file"
|
||||||
|
} >"$file.tmp"
|
||||||
|
else
|
||||||
|
# Insert new path comment after shebang
|
||||||
|
{
|
||||||
|
echo "$line1"
|
||||||
|
echo "$path_comment"
|
||||||
|
tail -n +2 "$file"
|
||||||
|
} >"$file.tmp"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
{
|
if [[ "$line1" == *"path: "* ]]; then
|
||||||
echo "$path_comment"
|
# Replace existing path comment on line 1
|
||||||
cat "$file"
|
{
|
||||||
} >"$file.tmp"
|
echo "$path_comment"
|
||||||
|
tail -n +2 "$file"
|
||||||
|
} >"$file.tmp"
|
||||||
|
else
|
||||||
|
# Insert new path comment at top
|
||||||
|
{
|
||||||
|
echo "$path_comment"
|
||||||
|
cat "$file"
|
||||||
|
} >"$file.tmp"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mv "$file.tmp" "$file"
|
mv "$file.tmp" "$file"
|
||||||
@@ -76,9 +80,26 @@ process_file() {
|
|||||||
if [[ -f "$target" ]]; then
|
if [[ -f "$target" ]]; then
|
||||||
process_file "$target"
|
process_file "$target"
|
||||||
elif [[ -d "$target" ]]; then
|
elif [[ -d "$target" ]]; then
|
||||||
|
find_cmd=(find "$target")
|
||||||
|
|
||||||
|
# Always exclude hidden files and directories
|
||||||
|
find_cmd+=(\( -name ".*" -prune \))
|
||||||
|
|
||||||
|
if [[ ${#excludes[@]} -gt 0 ]]; then
|
||||||
|
find_cmd+=(-o \()
|
||||||
|
for i in "${!excludes[@]}"; do
|
||||||
|
[[ $i -gt 0 ]] && find_cmd+=(-o)
|
||||||
|
find_cmd+=(-path "*/${excludes[$i]}" -prune)
|
||||||
|
find_cmd+=(-o -path "*/${excludes[$i]}/*" -prune)
|
||||||
|
done
|
||||||
|
find_cmd+=(\))
|
||||||
|
fi
|
||||||
|
|
||||||
|
find_cmd+=(-o -type f -print0)
|
||||||
|
|
||||||
while IFS= read -r -d '' file; do
|
while IFS= read -r -d '' file; do
|
||||||
process_file "$file"
|
process_file "$file"
|
||||||
done < <(find "$target" -type f -print0)
|
done < <("${find_cmd[@]}")
|
||||||
else
|
else
|
||||||
echo "Error: $target is not a file or directory" >&2
|
echo "Error: $target is not a file or directory" >&2
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
Submodule config/shared/nvim updated: b84e46bda1...2c8524df9d
@@ -44,6 +44,12 @@ bind -r j select-pane -D
|
|||||||
bind -r k select-pane -U
|
bind -r k select-pane -U
|
||||||
bind -r l select-pane -R
|
bind -r l select-pane -R
|
||||||
|
|
||||||
|
# Resize Opt/Alt-hjkl
|
||||||
|
bind -n M-h resize-pane -L 5
|
||||||
|
bind -n M-j resize-pane -D 5
|
||||||
|
bind -n M-k resize-pane -U 5
|
||||||
|
bind -n M-l resize-pane -R 5
|
||||||
|
|
||||||
# Last window instead of session
|
# Last window instead of session
|
||||||
bind ';' last-window
|
bind ';' last-window
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,26 @@ git_prompt_info() {
|
|||||||
echo " %F{green}($branch)%f"
|
echo " %F{green}($branch)%f"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
PROMPT='%n@%m%f %F{blue}%~%f$(git_prompt_info) $ '
|
abbrev_path() {
|
||||||
|
local pwd="${PWD/#$HOME/~}"
|
||||||
|
local parts=("${(@s:/:)pwd}")
|
||||||
|
local len=${#parts}
|
||||||
|
|
||||||
|
if (( len <= 1 )); then
|
||||||
|
echo "$pwd"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
local result=""
|
||||||
|
for (( i=1; i<len; i++ )); do
|
||||||
|
result+="${parts[i]:0:1}/"
|
||||||
|
done
|
||||||
|
result+="${parts[len]}"
|
||||||
|
echo "$result"
|
||||||
|
}
|
||||||
|
|
||||||
|
PROMPT='%n@%m%f %F{blue}$(abbrev_path)%f$(git_prompt_info) $ '
|
||||||
|
# PROMPT='%n@%m%f %F{blue}%~%f$(git_prompt_info) $ '
|
||||||
|
|
||||||
autoload -U up-line-or-beginning-search down-line-or-beginning-search
|
autoload -U up-line-or-beginning-search down-line-or-beginning-search
|
||||||
zle -N up-line-or-beginning-search
|
zle -N up-line-or-beginning-search
|
||||||
@@ -45,6 +64,10 @@ case "$OSTYPE" in
|
|||||||
darwin*) alias ls='ls --color=auto' ;;
|
darwin*) alias ls='ls --color=auto' ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
h() {
|
||||||
|
history 0 | grep -iE --color=always "$@" | tail -20
|
||||||
|
}
|
||||||
|
|
||||||
alias ll='ls -lF'
|
alias ll='ls -lF'
|
||||||
alias lla='ll -a'
|
alias lla='ll -a'
|
||||||
alias ld='ls -ld */'
|
alias ld='ls -ld */'
|
||||||
@@ -55,3 +78,5 @@ alias gp='git push'
|
|||||||
alias gst='git status'
|
alias gst='git status'
|
||||||
alias gd='git diff --patience --color-moved=dimmed-zebra --word-diff=plain --function-context --ignore-space-change -U3'
|
alias gd='git diff --patience --color-moved=dimmed-zebra --word-diff=plain --function-context --ignore-space-change -U3'
|
||||||
alias glg='git log --oneline --graph --decorate --all'
|
alias glg='git log --oneline --graph --decorate --all'
|
||||||
|
|
||||||
|
alias k='kubectl'
|
||||||
|
|||||||
Reference in New Issue
Block a user