make lint: Perform bash script linting
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Junegunn Choi · committed by Junegunn Choi · parent de0df24 · Browse files · 8 files·+83 added−48 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
8 files+83 added−48 removed
- other:+83 added−48 removed
Provenance
- Commit
f0c4ee4- Tree
45c711f- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
de0df24
8 files changed+83 added−48 removed
modified:shell/completion.bash+3 added-1 removed
29 unmodified lines30 # }31 32 ###########################################################33 34+#----BEGIN shfmt35 #----BEGIN INCLUDE common.sh36 # NOTE: Do not directly edit this section, which is copied from "common.sh".36-# To modify it, one can edit "common.sh" and run "./update-common.sh" to apply37+# To modify it, one can edit "common.sh" and run "./update.sh" to apply38 # the changes. See code comments in "common.sh" for the implementation details.39 40 __fzf_defaults() {41 printf '%s\n' "--height ${FZF_TMUX_HEIGHT:-40%} --min-height 20+ --bind=ctrl-z:ignore $1"641 unmodified lines683 *) __fzf_defc "$cmd" "$fn" "-o default -o bashdefault" ;;684 esac685 done686 }687+#----END shfmt688 689 fimodified:shell/completion.zsh+1 added-1 removed
96 unmodified lines97 ###########################################################98 99 #----BEGIN INCLUDE common.sh100 # NOTE: Do not directly edit this section, which is copied from "common.sh".101-# To modify it, one can edit "common.sh" and run "./update-common.sh" to apply101+# To modify it, one can edit "common.sh" and run "./update.sh" to apply102 # the changes. See code comments in "common.sh" for the implementation details.103 104 __fzf_defaults() {105 printf '%s\n' "--height ${FZF_TMUX_HEIGHT:-40%} --min-height 20+ --bind=ctrl-z:ignore $1"367 unmodified linesmodified:shell/key-bindings.bash+3 added-1 removed
15 unmodified lines16171819202122222324252627126 unmodified linesExpand all15415515615715815916015 unmodified lines
# Key bindings# ------------
#----BEGIN shfmt#----BEGIN INCLUDE common.sh# NOTE: Do not directly edit this section, which is copied from "common.sh".# To modify it, one can edit "common.sh" and run "./update-common.sh" to apply# To modify it, one can edit "common.sh" and run "./update.sh" to apply# the changes. See code comments in "common.sh" for the implementation details.
__fzf_defaults() { printf '%s\n' "--height ${FZF_TMUX_HEIGHT:-40%} --min-height 20+ --bind=ctrl-z:ignore $1"126 unmodified linesExpand all bind -m emacs-standard '"\ec": " \C-b\C-k \C-u`__fzf_cd__`\e\C-e\er\C-m\C-y\C-h\e \C-y\ey\C-x\C-x\C-d\C-y\ey\C-_"' bind -m vi-command '"\ec": "\C-z\ec\C-z"' bind -m vi-insert '"\ec": "\C-z\ec\C-z"'fi#----END shfmt
fimodified:shell/key-bindings.zsh+1 added-1 removed
38 unmodified lines39 if [[ -o interactive ]]; then40 41 #----BEGIN INCLUDE common.sh42 # NOTE: Do not directly edit this section, which is copied from "common.sh".43-# To modify it, one can edit "common.sh" and run "./update-common.sh" to apply43+# To modify it, one can edit "common.sh" and run "./update.sh" to apply44 # the changes. See code comments in "common.sh" for the implementation details.45 46 __fzf_defaults() {47 printf '%s\n' "--height ${FZF_TMUX_HEIGHT:-40%} --min-height 20+ --bind=ctrl-z:ignore $1"115 unmodified linesdeleted:shell/update-common.sh-31 removed
12345678910111213141516171819202122232425262728293031#!/bin/sh
# This script applies the contents of "common.sh" to the other files.
set -e
# Go to the directory that contains this scriptdir=${0%"${0##*/}"}if [ -n "$dir" ]; then cd "$dir"fi
update() { { sed -n '1,/^#----BEGIN INCLUDE common\.sh/p' "$1" cat <<EOF# NOTE: Do not directly edit this section, which is copied from "common.sh".# To modify it, one can edit "common.sh" and run "./update-common.sh" to apply# the changes. See code comments in "common.sh" for the implementation details.EOF grep -v '^[[:blank:]]*#' common.sh # remove code comments in common.sh sed -n '/^#----END INCLUDE/,$p' "$1" } > "$1.part"
mv -f "$1.part" "$1"}
update completion.bashupdate completion.zshupdate key-bindings.bashupdate key-bindings.zshadded:shell/update.sh+67 added
1+#!/usr/bin/env bash2+3+# This script applies the contents of "common.sh" to the other files.4+5+set -e6+7+dir=${0%"${0##*/}"}8+9+update() {10+ {11+ sed -n '1,/^#----BEGIN INCLUDE common\.sh/p' "$1"12+ cat <<EOF13+# NOTE: Do not directly edit this section, which is copied from "common.sh".14+# To modify it, one can edit "common.sh" and run "./update.sh" to apply15+# the changes. See code comments in "common.sh" for the implementation details.16+EOF17+ grep -v '^[[:blank:]]*#' "$dir/common.sh" # remove code comments in common.sh18+ sed -n '/^#----END INCLUDE/,$p' "$1"19+ } > "$1.part"20+21+ mv -f "$1.part" "$1"22+}23+24+update "$dir/completion.bash"25+update "$dir/completion.zsh"26+update "$dir/key-bindings.bash"27+update "$dir/key-bindings.zsh"28+29+# Check if --check is in ARGV30+check=031+rest=()32+for arg in "$@"; do33+ case $arg in34+ --check) check=1 ;;35+ *) rest+=("$arg") ;;36+ esac37+done38+39+fmt() {40+ if ! grep -q "^#----BEGIN shfmt" "$1"; then41+ if [[ $check == 1 ]]; then42+ shfmt -d "$1"43+ return $?44+ else45+ shfmt -w "$1"46+ fi47+ else48+ {49+ sed -n '1,/^#----BEGIN shfmt/p' "$1" | sed '$d'50+ sed -n '/^#----BEGIN shfmt/,/^#----END shfmt/p' "$1" | shfmt --filename "$1"51+ sed -n '/^#----END shfmt/,$p' "$1" | sed '1d'52+ } > "$1.part"53+54+ if [[ $check == 1 ]]; then55+ diff -q "$1" "$1.part"56+ ret=$?57+ rm -f "$1.part"58+ return $ret59+ fi60+61+ mv -f "$1.part" "$1"62+ fi63+}64+65+for file in "${rest[@]}"; do66+ fmt "$file" || exit $?67+donemodified:.tool-versions+2 added-1 removed
1 golang 1.232-ruby 3.42+ruby 3.43+shfmt 3.12modified:Makefile+6 added-12 removed
8 unmodified lines9 $(ROOT_DIR)/bin/fzf-tmux \10 $(ROOT_DIR)/install \11 $(ROOT_DIR)/uninstall \12 $(ROOT_DIR)/shell/common.sh \13- $(ROOT_DIR)/shell/update-common.sh14-BASH_SCRIPTS_INDENT_LEFT := $(ROOT_DIR)/shell/completion.bash \15- $(ROOT_DIR)/shell/key-bindings.bash13+ $(ROOT_DIR)/shell/update.sh \14+ $(ROOT_DIR)/shell/completion.bash \15+ $(ROOT_DIR)/shell/key-bindings.bash16 17 ifdef FZF_VERSION18 VERSION := $(FZF_VERSION)19 else79 unmodified lines99 100 lint: $(SOURCES) test/*.rb test/lib/*.rb ${BASH_SCRIPTS}101 [ -z "$$(gofmt -s -d src)" ] || (gofmt -s -d src; exit 1)102 bundle exec rubocop -a --require rubocop-minitest --require rubocop-performance103- [ -z "$$(shfmt -d $(BASH_SCRIPTS))" ] || (echo "format bash files by (make fmt)"; exit 1)103+ shell/update.sh --check ${BASH_SCRIPTS}104 105-fmt: $(SOURCES) $(BASH_SCRIPTS) $(BASH_SCRIPTS_INDENT_LEFT)105+fmt: $(SOURCES) $(BASH_SCRIPTS)106 gofmt -s -w src107- shfmt -w $(BASH_SCRIPTS)108- # shift left because we have an outermost if block for historical reasons.109- for f in $(BASH_SCRIPTS_INDENT_LEFT); do \110- shfmt -w "$$f"; \111- tmp=$$(mktemp); \112- sed 's/^ //' "$$f" > "$$tmp" && mv "$$tmp" "$$f"; \113- done107+ shell/update.sh ${BASH_SCRIPTS}108 109 install: bin/fzf110 111 generate:95 unmodified lines