Skip to content

Commit

Permalink
shfmt -i 2 -w config/{.bin,.config/zsh}
Browse files Browse the repository at this point in the history
  • Loading branch information
izumin5210 committed May 19, 2024
1 parent f370821 commit d04088c
Show file tree
Hide file tree
Showing 12 changed files with 172 additions and 174 deletions.
34 changes: 17 additions & 17 deletions config/.bin/git-clean-branch
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ set -eu

clean_local() {
local base=${1:-$(git default-branch)}
git branch --merged \
| grep -v ${base} \
| grep -v '*' \
| grep -v '^\s*$' \
| {
git branch --merged |
grep -v ${base} |
grep -v '*' |
grep -v '^\s*$' |
{
local target=$(cat)
if [ ${#target} -gt 0 ]; then
git branch -d ${target}
Expand All @@ -23,11 +23,11 @@ clean_local() {
clean_remote() {
local remote=${1:-origin}
local base=${2:-$(git default-branch)}
git branch --remotes --merged \
| grep ${remote}/ \
| grep -v ${base} \
| sed s~${remote}/~:~ \
| {
git branch --remotes --merged |
grep ${remote}/ |
grep -v ${base} |
sed s~${remote}/~:~ |
{
local target=$(cat)
if [ ${#target} -gt 0 ]; then
git push origin $target
Expand All @@ -46,16 +46,16 @@ target="$1"
shift

case ${target} in
local|l)
clean_local
local | l)
clean_local
;;

remote|r)
clean_remote
remote | r)
clean_remote
;;

*)
printutil error "Invalid target"
exit 1
*)
printutil error "Invalid target"
exit 1
;;
esac
41 changes: 20 additions & 21 deletions config/.bin/git-create-repo
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ create() {

local path="$(pwd)/${name}"

if type ghq > /dev/null 2>&1; then
if type ghq >/dev/null 2>&1; then
src_dir=$(ghq root)
if [ -n "${src_dir}" ]; then
path="${src_dir}/github.com/${repo}"
Expand Down Expand Up @@ -87,39 +87,38 @@ is_sandbox=0
is_private=0
github_sandbox="${github_user}-sandbox"

while [ $# -gt 0 ];
do
while [ $# -gt 0 ]; do
case ${1} in
--debug|-d)
set -x
--debug | -d)
set -x
;;

--sandbox|-s)
is_sandbox=1
--sandbox | -s)
is_sandbox=1
;;

--sandbox-name)
github_sandbox=${2}
shift
--sandbox-name)
github_sandbox=${2}
shift
;;

--private|-p)
is_private=1
--private | -p)
is_private=1
;;

--version|-v)
version
exit 0
--version | -v)
version
exit 0
;;

--help|-h)
usage $github_user $github_sandbox
exit 0
--help | -h)
usage $github_user $github_sandbox
exit 0
;;

*)
create $1 $github_user $is_sandbox $github_sandbox
exit 0
*)
create $1 $github_user $is_sandbox $github_sandbox
exit 0
;;
esac
shift
Expand Down
84 changes: 42 additions & 42 deletions config/.bin/git-info
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
set -euo pipefail

usage() {
cat <<EOF
cat <<EOF
$(basename ${0}) - Create a remote repository
Usage:
Expand All @@ -24,11 +24,11 @@ EOF
}

isInsideGitRepo() {
git rev-parse --is-inside-work-tree >/dev/null 2>&1
git rev-parse --is-inside-work-tree >/dev/null 2>&1
}

showRepoSlug() {
git rev-parse --show-toplevel |
git rev-parse --show-toplevel |
sed -e "s,^$HOME,~," |
sed -e "s,^~/src/\(github.com/\)\?,," |
shorten "slug" |
Expand Down Expand Up @@ -83,57 +83,57 @@ truncate() {
}

if [ $# -lt 1 ]; then
usage
exit 1
usage
exit 1
fi

if ! isInsideGitRepo; then
exit 1
exit 1
fi

while [ $# -gt 0 ]; do
case ${1} in
slug | path | branch | root)
subcmd="${1}"
;;

--short | -s)
withShort=true
;;

--max-len)
shift
maxLen="${1}"
;;

--help | -h)
usage
exit 0
;;

*)
usage
exit 1
;;
esac
shift
case ${1} in
slug | path | branch | root)
subcmd="${1}"
;;

--short | -s)
withShort=true
;;

--max-len)
shift
maxLen="${1}"
;;

--help | -h)
usage
exit 0
;;

*)
usage
exit 1
;;
esac
shift
done

case "${subcmd}" in
slug)
showRepoSlug
;;
showRepoSlug
;;
path)
showPath
;;
showPath
;;
branch)
showBranchName
;;
showBranchName
;;
root)
showRootPath
;;
showRootPath
;;
*)
usage
exit 1
;;
usage
exit 1
;;
esac
28 changes: 14 additions & 14 deletions config/.bin/git-interactive-add
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
set -euo pipefail

selectFiles() {
git status --short \
| fzf -n 2 --multi --exit-0 --expect=ctrl-d,ctrl-p --preview='git diff --color=always {2}'
}
git status --short |
fzf -n 2 --multi --exit-0 --expect=ctrl-d,ctrl-p --preview='git diff --color=always {2}'
}

out=$(selectFiles)
addfiles=$(tail -n +2 <<< "$out" | awk '{if (substr($0,2,1) !~ / /) print $2}')
addfiles=$(tail -n +2 <<<"$out" | awk '{if (substr($0,2,1) !~ / /) print $2}')

[[ -z "$addfiles" ]] && continue

case $(head -1 <<< "$out") in
ctrl-d)
git diff --color=always $addfiles | less -R
;;
ctrl-p)
git add -p $addfiles
;;
*)
git add $addfiles
;;
case $(head -1 <<<"$out") in
ctrl-d)
git diff --color=always $addfiles | less -R
;;
ctrl-p)
git add -p $addfiles
;;
*)
git add $addfiles
;;
esac
15 changes: 7 additions & 8 deletions config/.bin/git-interactive-checkout
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ listTargets() {
listTags
}

listTargets \
| fzf --no-hscroll --no-multi -n 2 --ansi \
| awk '{$1="";print $0}' \
| sed "s#remotes/[^/]*/##" \
| {
git checkout $(cat)
}

listTargets |
fzf --no-hscroll --no-multi -n 2 --ansi |
awk '{$1="";print $0}' |
sed "s#remotes/[^/]*/##" |
{
git checkout $(cat)
}
12 changes: 6 additions & 6 deletions config/.bin/git-interactive-fixup
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ git log \
--oneline \
--no-merges \
--color \
--pretty=format:"%C(Yellow)%h%Creset - %s %C(green)<%cr>%Creset %Cblue(%an)%Creset" \
| fzf --ansi \
| awk '{ print $1 }' \
| {
git commit --fixup $(cat)
}
--pretty=format:"%C(Yellow)%h%Creset - %s %C(green)<%cr>%Creset %Cblue(%an)%Creset" |
fzf --ansi |
awk '{ print $1 }' |
{
git commit --fixup $(cat)
}
18 changes: 9 additions & 9 deletions config/.bin/git-wip-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

set -euo pipefail

branch=`git rev-parse --abbrev-ref @`
branch=$(git rev-parse --abbrev-ref @)

if [ $branch = "$(git default-branch)" ]; then
echo "Current branch is NOT a feature branch."
exit 1
echo "Current branch is NOT a feature branch."
exit 1
else
git add --all
git add --all

if git log -1 --pretty='%s' | grep -q -e "^\[WIP\]"; then
git commit --amend --verbose --allow-empty
else
git commit --edit --verbose --allow-empty --message "[WIP] "
fi
if git log -1 --pretty='%s' | grep -q -e "^\[WIP\]"; then
git commit --amend --verbose --allow-empty
else
git commit --edit --verbose --allow-empty --message "[WIP] "
fi
fi
Loading

0 comments on commit d04088c

Please sign in to comment.