Skip to content

Commit

Permalink
Meta: add an .editorconfig and apply it to the codebase (#404)
Browse files Browse the repository at this point in the history
  • Loading branch information
suft authored Nov 6, 2024
1 parent 2d5f8f4 commit 7a40a11
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 184 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = space
insert_final_newline = true
tab_width = 4
trim_trailing_whitespace = true
10 changes: 5 additions & 5 deletions bin/git-forgit
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ _forgit_list_files() {
# unquoted.
# uniq is necessary because unmerged files are printed once for each
# merge conflict.
# With the -z flag, git also uses \0 line termination, so we
# With the -z flag, git also uses \0 line termination, so we
# have to replace the terminators.
git ls-files -z "$@" "$rootdir" | tr '\0' '\n' | uniq
}
Expand Down Expand Up @@ -556,7 +556,7 @@ _forgit_cherry_pick() {
[[ -z $1 ]] && echo "Please specify target branch" && return 1
target="$1"

# in this function, we do something interesting to maintain proper ordering as it's assumed
# in this function, we do something interesting to maintain proper ordering as it's assumed
# you generally want to cherry pick oldest->newest when you multiselect
# The instances of "cut", "nl" and "sort" all serve this purpose
# Please see https://github.com/wfxr/forgit/issues/253 for more details
Expand All @@ -580,7 +580,7 @@ _forgit_cherry_pick() {
commits+=("$commit")
done < <(echo "$fzf_selection" | sort -n -k 1 | cut -f2 | cut -d' ' -f1 | _forgit_reverse_lines)
[ ${#commits[@]} -eq 0 ] && return 1

_forgit_cherry_pick_git_opts=()
_forgit_parse_array _forgit_cherry_pick_git_opts "$FORGIT_CHERRY_PICK_GIT_OPTS"
git cherry-pick "${_forgit_cherry_pick_git_opts[@]}" "${commits[@]}"
Expand Down Expand Up @@ -883,7 +883,7 @@ _forgit_revert_commit() {
graph=()
[[ $_forgit_log_graph_enable == true ]] && graph=(--graph)

# in this function, we do something interesting to maintain proper ordering as it's assumed
# in this function, we do something interesting to maintain proper ordering as it's assumed
# you generally want to revert newest->oldest when you multiselect
# The instances of "cut", "nl" and "sort" all serve this purpose
# Please see https://github.com/wfxr/forgit/issues/253 for more details
Expand All @@ -896,7 +896,7 @@ _forgit_revert_commit() {
_forgit_emojify |
nl |
FZF_DEFAULT_OPTS="$opts" fzf |
sort -n -k 1 |
sort -n -k 1 |
cut -f2- |
sed 's/^[^a-f^0-9]*\([a-f0-9]*\).*/\1/')

Expand Down
138 changes: 69 additions & 69 deletions completions/_git-forgit
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
# tab completions for forgit.

_git-branches() {
_alternative "branches:branchname:($(git branch -a --format '%(refname:short)'))"
_alternative "branches:branchname:($(git branch -a --format '%(refname:short)'))"
}

_git-checkout-file() {
_alternative "files:filename:($(git ls-files --modified))"
_alternative "files:filename:($(git ls-files --modified))"
}

_git-stash-show() {
_alternative "files:filename:($(git stash list | sed -n -e 's/:.*//p'))"
_alternative "files:filename:($(git stash list | sed -n -e 's/:.*//p'))"
}

# The completions for git already define a _git-diff completion function, but
Expand All @@ -24,80 +24,80 @@ _git-stash-show() {
# $CURRENT), so we use a simplified version here which always provides the same
# results independent of the context.
_git-forgit-diff() {
_alternative \
'commit-ranges::__git_commit_ranges' \
'blobs-and-trees-in-treeish::__git_blobs_and_trees_in_treeish' \
'files::__git_changed-in-working-tree_files' \
'blobs::__git_blobs '
_alternative \
'commit-ranges::__git_commit_ranges' \
'blobs-and-trees-in-treeish::__git_blobs_and_trees_in_treeish' \
'files::__git_changed-in-working-tree_files' \
'blobs::__git_blobs '
}

_git-staged() {
_alternative "files:filename:($(git diff --name-only --staged))"
_alternative "files:filename:($(git diff --name-only --staged))"
}

_git-forgit-reflog() {
declare -a cmds
cmds=('expire:prune old reflog entries' 'delete:delete entries from reflog' 'show:show log of ref' 'exists:check whether a ref has a reflog')
_alternative 'cmds:: _describe -t cmds cmd cmds' 'refs:: __git_references'
declare -a cmds
cmds=('expire:prune old reflog entries' 'delete:delete entries from reflog' 'show:show log of ref' 'exists:check whether a ref has a reflog')
_alternative 'cmds:: _describe -t cmds cmd cmds' 'refs:: __git_references'
}

_git-forgit() {
local subcommand cmd
subcommand="${words[1]}"
if [[ "$subcommand" != "forgit"* ]]; then
# Forgit is obviously called via a git alias. Get the original
# aliased subcommand and proceed as if it was the previous word.
cmd=$(git config --get "alias.$subcommand" | cut -d ' ' -f 2)
else
# The last word is the relevant command
cmd=${words[(( ${#words} - 1 ))]}
fi
case ${cmd} in
forgit)
local -a subcommands
subcommands=(
'add:git add selector'
'blame:git blame viewer'
'branch_delete:git branch deletion selector'
'checkout_branch:git checkout branch selector'
'checkout_commit:git checkout commit selector'
'checkout_file:git checkout-file selector'
'checkout_tag:git checkout tag selector'
'cherry_pick:git cherry-picking'
'cherry_pick_from_branch:git cherry-picking with interactive branch selection'
'clean:git clean selector'
'diff:git diff viewer'
'fixup:git fixup'
'ignore:git ignore generator'
'log:git commit viewer'
'reflog:git reflog viewer'
'rebase:git rebase'
'reset_head:git reset HEAD (unstage) selector'
'revert_commit:git revert commit selector'
'stash_show:git stash viewer'
'stash_push:git stash push selector'
)
_describe -t commands 'git forgit' subcommands
;;
add) _git-add ;;
branch_delete) _git-branches ;;
checkout_branch) _git-branches ;;
checkout_commit) __git_recent_commits ;;
checkout_file) _git-checkout-file ;;
checkout_tag) __git_tags ;;
cherry_pick) _git-cherry-pick ;;
cherry_pick_from_branch) _git-branches ;;
clean) _git-clean ;;
diff) _git-forgit-diff ;;
fixup) __git_branch_names ;;
log) _git-log ;;
reflog) _git-forgit-reflog ;;
rebase) _git-rebase ;;
reset_head) _git-staged ;;
revert_commit) __git_recent_commits ;;
stash_show) _git-stash-show ;;
esac
local subcommand cmd
subcommand="${words[1]}"
if [[ "$subcommand" != "forgit"* ]]; then
# Forgit is obviously called via a git alias. Get the original
# aliased subcommand and proceed as if it was the previous word.
cmd=$(git config --get "alias.$subcommand" | cut -d ' ' -f 2)
else
# The last word is the relevant command
cmd=${words[(( ${#words} - 1 ))]}
fi

case ${cmd} in
forgit)
local -a subcommands
subcommands=(
'add:git add selector'
'blame:git blame viewer'
'branch_delete:git branch deletion selector'
'checkout_branch:git checkout branch selector'
'checkout_commit:git checkout commit selector'
'checkout_file:git checkout-file selector'
'checkout_tag:git checkout tag selector'
'cherry_pick:git cherry-picking'
'cherry_pick_from_branch:git cherry-picking with interactive branch selection'
'clean:git clean selector'
'diff:git diff viewer'
'fixup:git fixup'
'ignore:git ignore generator'
'log:git commit viewer'
'reflog:git reflog viewer'
'rebase:git rebase'
'reset_head:git reset HEAD (unstage) selector'
'revert_commit:git revert commit selector'
'stash_show:git stash viewer'
'stash_push:git stash push selector'
)
_describe -t commands 'git forgit' subcommands
;;
add) _git-add ;;
branch_delete) _git-branches ;;
checkout_branch) _git-branches ;;
checkout_commit) __git_recent_commits ;;
checkout_file) _git-checkout-file ;;
checkout_tag) __git_tags ;;
cherry_pick) _git-cherry-pick ;;
cherry_pick_from_branch) _git-branches ;;
clean) _git-clean ;;
diff) _git-forgit-diff ;;
fixup) __git_branch_names ;;
log) _git-log ;;
reflog) _git-forgit-reflog ;;
rebase) _git-rebase ;;
reset_head) _git-staged ;;
revert_commit) __git_recent_commits ;;
stash_show) _git-stash-show ;;
esac
}

# We're reusing existing completion functions, so load those first
Expand All @@ -124,7 +124,7 @@ compdef __git_recent_commits forgit::revert::commit
compdef _git-stash-show forgit::stash::show

# this is the case of calling the command and pressing tab
# the very first time of a shell session, we have to manually
# the very first time of a shell session, we have to manually
# call the dispatch function
if [[ $funcstack[1] == "_git-forgit" ]]; then
_git-forgit "$@"
Expand Down
Loading

0 comments on commit 7a40a11

Please sign in to comment.