From 7a40a11e795f42c851eefbb2fd39419383c66ccd Mon Sep 17 00:00:00 2001 From: Sufien Tout Date: Wed, 6 Nov 2024 04:10:27 -0500 Subject: [PATCH] Meta: add an .editorconfig and apply it to the codebase (#404) --- .editorconfig | 9 ++ bin/git-forgit | 10 +- completions/_git-forgit | 138 +++++++++++----------- completions/git-forgit.bash | 220 ++++++++++++++++++------------------ 4 files changed, 193 insertions(+), 184 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..2b44368 --- /dev/null +++ b/.editorconfig @@ -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 diff --git a/bin/git-forgit b/bin/git-forgit index 7f96f9d..4aebe59 100755 --- a/bin/git-forgit +++ b/bin/git-forgit @@ -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 } @@ -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 @@ -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[@]}" @@ -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 @@ -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/') diff --git a/completions/_git-forgit b/completions/_git-forgit index 7760511..b26e4db 100644 --- a/completions/_git-forgit +++ b/completions/_git-forgit @@ -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 @@ -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 @@ -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 "$@" diff --git a/completions/git-forgit.bash b/completions/git-forgit.bash index 9f500a8..80a443f 100755 --- a/completions/git-forgit.bash +++ b/completions/git-forgit.bash @@ -12,27 +12,27 @@ _git_branch_delete() { - __gitcomp_nl "$(__git_heads)" + __gitcomp_nl "$(__git_heads)" } _git_checkout_branch() { - __gitcomp_nl "$(__git branch -a --format '%(refname:short)')" + __gitcomp_nl "$(__git branch -a --format '%(refname:short)')" } _git_checkout_file() { - __gitcomp_nl "$(__git ls-files --modified)" + __gitcomp_nl "$(__git ls-files --modified)" } _git_checkout_tag() { - __gitcomp_nl "$(__git_tags)" + __gitcomp_nl "$(__git_tags)" } _git_stash_show() { - __gitcomp_nl "$(__git stash list | sed -n -e 's/:.*//p')" + __gitcomp_nl "$(__git stash list | sed -n -e 's/:.*//p')" } # Completion for git-forgit @@ -40,120 +40,120 @@ _git_stash_show() # correctly complete available branches on "git cb". _git_forgit() { - local subcommand cword cur prev cmds + local subcommand cword cur prev cmds - subcommand="${COMP_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. - prev=$(git config --get "alias.$subcommand" | cut -d' ' -f 2) - cword=$((${COMP_CWORD} + 1)) - else - cword=${COMP_CWORD} - prev=${COMP_WORDS[COMP_CWORD-1]} - fi + subcommand="${COMP_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. + prev=$(git config --get "alias.$subcommand" | cut -d' ' -f 2) + cword=$((${COMP_CWORD} + 1)) + else + cword=${COMP_CWORD} + prev=${COMP_WORDS[COMP_CWORD-1]} + fi - cur=${COMP_WORDS[COMP_CWORD]} + cur=${COMP_WORDS[COMP_CWORD]} - cmds=" - add - blame - branch_delete - checkout_branch - checkout_commit - checkout_file - checkout_tag - cherry_pick - cherry_pick_from_branch - clean - diff - fixup - ignore - log - reflog - rebase - reset_head - revert_commit - stash_show - stash_push - " + cmds=" + add + blame + branch_delete + checkout_branch + checkout_commit + checkout_file + checkout_tag + cherry_pick + cherry_pick_from_branch + clean + diff + fixup + ignore + log + reflog + rebase + reset_head + revert_commit + stash_show + stash_push + " - case ${cword} in - 2) - COMPREPLY=($(compgen -W "${cmds}" -- ${cur})) - ;; - 3) - case ${prev} in - add) _git_add ;; - branch_delete) _git_branch_delete ;; - checkout_branch) _git_checkout_branch ;; - checkout_commit) _git_checkout ;; - checkout_file) _git_checkout_file ;; - checkout_tag) _git_checkout_tag ;; - cherry_pick) _git_cherry_pick ;; - cherry_pick_from_branch) _git_checkout_branch ;; - clean) _git_clean ;; - diff) _git_diff ;; - fixup) _git_branch ;; - log) _git_log ;; - reflog) _git_reflog ;; - rebase) _git_rebase ;; - reset_head) _git_reset ;; - revert_commit) _git_revert ;; - stash_show) _git_stash_show ;; - esac - ;; - *) - COMPREPLY=() - ;; - esac + case ${cword} in + 2) + COMPREPLY=($(compgen -W "${cmds}" -- ${cur})) + ;; + 3) + case ${prev} in + add) _git_add ;; + branch_delete) _git_branch_delete ;; + checkout_branch) _git_checkout_branch ;; + checkout_commit) _git_checkout ;; + checkout_file) _git_checkout_file ;; + checkout_tag) _git_checkout_tag ;; + cherry_pick) _git_cherry_pick ;; + cherry_pick_from_branch) _git_checkout_branch ;; + clean) _git_clean ;; + diff) _git_diff ;; + fixup) _git_branch ;; + log) _git_log ;; + reflog) _git_reflog ;; + rebase) _git_rebase ;; + reset_head) _git_reset ;; + revert_commit) _git_revert ;; + stash_show) _git_stash_show ;; + esac + ;; + *) + COMPREPLY=() + ;; + esac } # Check if forgit plugin is loaded if [[ $(type -t forgit::add) == function ]] then - # We're reusing existing git completion functions, so load those first - # and check if completion function exists afterwards. - _completion_loader git - [[ $(type -t __git_complete) == function ]] || return 1 + # We're reusing existing git completion functions, so load those first + # and check if completion function exists afterwards. + _completion_loader git + [[ $(type -t __git_complete) == function ]] || return 1 - # Completion for forgit plugin shell functions - __git_complete forgit::add _git_add - __git_complete forgit::branch::delete _git_branch_delete - __git_complete forgit::checkout::branch _git_checkout_branch - __git_complete forgit::checkout::commit _git_checkout - __git_complete forgit::checkout::file _git_checkout_file - __git_complete forgit::checkout::tag _git_checkout_tag - __git_complete forgit::cherry::pick _git_cherry_pick - __git_complete forgit::cherry::pick::from::branch _git_checkout_branch - __git_complete forgit::clean _git_clean - __git_complete forgit::diff _git_diff - __git_complete forgit::fixup _git_branch - __git_complete forgit::log _git_log - __git_complete forgit::reflog _git_reflog - __git_complete forgit::rebase _git_rebase - __git_complete forgit::reset::head _git_reset - __git_complete forgit::revert::commit _git_revert - __git_complete forgit::stash::show _git_stash_show + # Completion for forgit plugin shell functions + __git_complete forgit::add _git_add + __git_complete forgit::branch::delete _git_branch_delete + __git_complete forgit::checkout::branch _git_checkout_branch + __git_complete forgit::checkout::commit _git_checkout + __git_complete forgit::checkout::file _git_checkout_file + __git_complete forgit::checkout::tag _git_checkout_tag + __git_complete forgit::cherry::pick _git_cherry_pick + __git_complete forgit::cherry::pick::from::branch _git_checkout_branch + __git_complete forgit::clean _git_clean + __git_complete forgit::diff _git_diff + __git_complete forgit::fixup _git_branch + __git_complete forgit::log _git_log + __git_complete forgit::reflog _git_reflog + __git_complete forgit::rebase _git_rebase + __git_complete forgit::reset::head _git_reset + __git_complete forgit::revert::commit _git_revert + __git_complete forgit::stash::show _git_stash_show - # Completion for forgit plugin shell aliases - if [[ -z "$FORGIT_NO_ALIASES" ]]; then - __git_complete "${forgit_add}" _git_add - __git_complete "${forgit_branch_delete}" _git_branch_delete - __git_complete "${forgit_checkout_branch}" _git_checkout_branch - __git_complete "${forgit_checkout_commit}" _git_checkout - __git_complete "${forgit_checkout_file}" _git_checkout_file - __git_complete "${forgit_checkout_tag}" _git_checkout_tag - __git_complete "${forgit_cherry_pick}" _git_checkout_branch - __git_complete "${forgit_clean}" _git_clean - __git_complete "${forgit_diff}" _git_diff - __git_complete "${forgit_fixup}" _git_branch - __git_complete "${forgit_log}" _git_log - __git_complete "${forgit_reflog}" _git_reflog - __git_complete "${forgit_rebase}" _git_rebase - __git_complete "${forgit_reset_head}" _git_reset - __git_complete "${forgit_revert_commit}" _git_revert - __git_complete "${forgit_stash_show}" _git_stash_show - fi + # Completion for forgit plugin shell aliases + if [[ -z "$FORGIT_NO_ALIASES" ]]; then + __git_complete "${forgit_add}" _git_add + __git_complete "${forgit_branch_delete}" _git_branch_delete + __git_complete "${forgit_checkout_branch}" _git_checkout_branch + __git_complete "${forgit_checkout_commit}" _git_checkout + __git_complete "${forgit_checkout_file}" _git_checkout_file + __git_complete "${forgit_checkout_tag}" _git_checkout_tag + __git_complete "${forgit_cherry_pick}" _git_checkout_branch + __git_complete "${forgit_clean}" _git_clean + __git_complete "${forgit_diff}" _git_diff + __git_complete "${forgit_fixup}" _git_branch + __git_complete "${forgit_log}" _git_log + __git_complete "${forgit_reflog}" _git_reflog + __git_complete "${forgit_rebase}" _git_rebase + __git_complete "${forgit_reset_head}" _git_reset + __git_complete "${forgit_revert_commit}" _git_revert + __git_complete "${forgit_stash_show}" _git_stash_show + fi fi