From f0c4ee4047f3b70241bacab712642437e37fad2f Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Wed, 24 Sep 2025 20:47:22 +0900 Subject: make lint: Perform bash script linting --- shell/update.sh | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 shell/update.sh (limited to 'shell/update.sh') diff --git a/shell/update.sh b/shell/update.sh new file mode 100755 index 00000000..4b6f63ae --- /dev/null +++ b/shell/update.sh @@ -0,0 +1,67 @@ +#!/usr/bin/env bash + +# This script applies the contents of "common.sh" to the other files. + +set -e + +dir=${0%"${0##*/}"} + +update() { + { + sed -n '1,/^#----BEGIN INCLUDE common\.sh/p' "$1" + cat < "$1.part" + + mv -f "$1.part" "$1" +} + +update "$dir/completion.bash" +update "$dir/completion.zsh" +update "$dir/key-bindings.bash" +update "$dir/key-bindings.zsh" + +# Check if --check is in ARGV +check=0 +rest=() +for arg in "$@"; do + case $arg in + --check) check=1 ;; + *) rest+=("$arg") ;; + esac +done + +fmt() { + if ! grep -q "^#----BEGIN shfmt" "$1"; then + if [[ $check == 1 ]]; then + shfmt -d "$1" + return $? + else + shfmt -w "$1" + fi + else + { + sed -n '1,/^#----BEGIN shfmt/p' "$1" | sed '$d' + sed -n '/^#----BEGIN shfmt/,/^#----END shfmt/p' "$1" | shfmt --filename "$1" + sed -n '/^#----END shfmt/,$p' "$1" | sed '1d' + } > "$1.part" + + if [[ $check == 1 ]]; then + diff -q "$1" "$1.part" + ret=$? + rm -f "$1.part" + return $ret + fi + + mv -f "$1.part" "$1" + fi +} + +for file in "${rest[@]}"; do + fmt "$file" || exit $? +done -- cgit v1.2.3