From 2ab3ea5482beb2cb3b0fb9360a926912d3c72007 Mon Sep 17 00:00:00 2001 From: syui Date: Fri, 3 Apr 2026 21:23:49 +0900 Subject: [PATCH] fix ln local bin --- .local/bin/git-ci | 11 +++++++- .local/bin/git-orphan | 8 +++++- .local/bin/vren | 64 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 80 insertions(+), 3 deletions(-) mode change 120000 => 100755 .local/bin/git-ci mode change 120000 => 100755 .local/bin/git-orphan mode change 120000 => 100755 .local/bin/vren diff --git a/.local/bin/git-ci b/.local/bin/git-ci deleted file mode 120000 index d5642e8..0000000 --- a/.local/bin/git-ci +++ /dev/null @@ -1 +0,0 @@ -/Users/syui/dotfiles/.local/bin/git-ci \ No newline at end of file diff --git a/.local/bin/git-ci b/.local/bin/git-ci new file mode 100755 index 0000000..1bf3eeb --- /dev/null +++ b/.local/bin/git-ci @@ -0,0 +1,10 @@ +#!/bin/bash +if [ $# -eq 0 ]; then + git commit -v +else + if [ "$1" = "--amend" ]; then + git commit -v --amend + else + git commit -m "$*" + fi +fi diff --git a/.local/bin/git-orphan b/.local/bin/git-orphan deleted file mode 120000 index 7135546..0000000 --- a/.local/bin/git-orphan +++ /dev/null @@ -1 +0,0 @@ -/Users/syui/dotfiles/.local/bin/git-orphan \ No newline at end of file diff --git a/.local/bin/git-orphan b/.local/bin/git-orphan new file mode 100755 index 0000000..f969103 --- /dev/null +++ b/.local/bin/git-orphan @@ -0,0 +1,7 @@ +#!/bin/bash +git checkout --orphan temp +git add -A +git commit -m "init" +git branch -D main +git branch -m temp main +# git push -f origin main diff --git a/.local/bin/vren b/.local/bin/vren deleted file mode 120000 index 4877c80..0000000 --- a/.local/bin/vren +++ /dev/null @@ -1 +0,0 @@ -/Users/syui/dotfiles/.local/bin/vren \ No newline at end of file diff --git a/.local/bin/vren b/.local/bin/vren new file mode 100755 index 0000000..f0ac5b6 --- /dev/null +++ b/.local/bin/vren @@ -0,0 +1,63 @@ +#!/bin/zsh +# vren - rename files with vim +# usage: vren [dir] + +dir="${1:-.}" +cd "$dir" || exit 1 + +# git init if no .git +has_git=0 +if [ -d .git ]; then + has_git=1 +else + git init -q + git add -A + git commit -q -m "before rename" +fi + +# list files +old=$(mktemp) +new=$(mktemp) +ls -1 > "$old" +cp "$old" "$new" + +# edit +vim "$new" + +# check +old_count=$(wc -l < "$old") +new_count=$(wc -l < "$new") +if [ "$old_count" -ne "$new_count" ]; then + echo "error: line count mismatch ($old_count -> $new_count)" + rm "$old" "$new" + exit 1 +fi + +# diff +paste "$old" "$new" | while IFS=$'\t' read -r o n; do + [ "$o" != "$n" ] && echo " $o -> $n" +done + +if ! diff -q "$old" "$new" >/dev/null 2>&1; then + echo "" + printf "apply? (y/n): " + read -q ans + echo "" + if [ "$ans" = "y" ]; then + paste "$old" "$new" | while IFS=$'\t' read -r o n; do + [ "$o" != "$n" ] && mv -- "$o" "$n" + done + echo "done" + if [ "$has_git" -eq 0 ]; then + git add -A + git commit -q -m "after rename" + echo "restore: git log / git checkout HEAD~1 -- ." + fi + else + echo "cancelled" + fi +else + echo "no changes" +fi + +rm "$old" "$new"