diff options
Diffstat (limited to 'shell')
| -rw-r--r-- | shell/completion.bash | 4 | ||||
| -rw-r--r-- | shell/completion.zsh | 2 | ||||
| -rw-r--r-- | shell/key-bindings.bash | 4 | ||||
| -rw-r--r-- | shell/key-bindings.zsh | 2 | ||||
| -rwxr-xr-x | shell/update-common.sh | 31 | ||||
| -rwxr-xr-x | shell/update.sh | 67 |
6 files changed, 75 insertions, 35 deletions
diff --git a/shell/completion.bash b/shell/completion.bash index 965bdb40..e41feb9f 100644 --- a/shell/completion.bash +++ b/shell/completion.bash @@ -31,9 +31,10 @@ if [[ $- =~ i ]]; then ########################################################### +#----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() { @@ -683,5 +684,6 @@ _fzf_setup_completion() { esac done } +#----END shfmt fi diff --git a/shell/completion.zsh b/shell/completion.zsh index 1df53f55..39e72db2 100644 --- a/shell/completion.zsh +++ b/shell/completion.zsh @@ -98,7 +98,7 @@ if [[ -o interactive ]]; then #----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() { diff --git a/shell/key-bindings.bash b/shell/key-bindings.bash index b83d26a0..500591bc 100644 --- a/shell/key-bindings.bash +++ b/shell/key-bindings.bash @@ -17,9 +17,10 @@ if [[ $- =~ i ]]; then # 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() { @@ -154,5 +155,6 @@ if [[ "${FZF_ALT_C_COMMAND-x}" != "" ]]; then bind -m vi-command '"\ec": "\C-z\ec\C-z"' bind -m vi-insert '"\ec": "\C-z\ec\C-z"' fi +#----END shfmt fi diff --git a/shell/key-bindings.zsh b/shell/key-bindings.zsh index 46b3c2b0..bc2c8968 100644 --- a/shell/key-bindings.zsh +++ b/shell/key-bindings.zsh @@ -40,7 +40,7 @@ if [[ -o interactive ]]; then #----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() { diff --git a/shell/update-common.sh b/shell/update-common.sh deleted file mode 100755 index 55905043..00000000 --- a/shell/update-common.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/sh - -# This script applies the contents of "common.sh" to the other files. - -set -e - -# Go to the directory that contains this script -dir=${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.bash -update completion.zsh -update key-bindings.bash -update key-bindings.zsh 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 <<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.sh" to apply +# the changes. See code comments in "common.sh" for the implementation details. +EOF + grep -v '^[[:blank:]]*#' "$dir/common.sh" # remove code comments in common.sh + sed -n '/^#----END INCLUDE/,$p' "$1" + } > "$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 |
