update.sh
This file
Path
shell/update.sh
68 lines · 1.4 KiB · Shell
Last changed by
fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
History of this fileTake it
The walk stopped after 200 commits: lines older than 76efddd point at it.
bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 1–10why, one step back1#!/usr/bin/env bash23# This script applies the contents of "common.sh" to the other files.45set -e67dir=${0%"${0##*/}"}89update() {10 {fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
line 11why, one step back11 sed -n '1,/^#----BEGIN INCLUDE common\.sh/p' "$1"bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
line 12why, one step back12 cat << EOFfish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
lines 13–15why, one step back13# 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.bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 16–17why, one step back16EOF17 echofish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
lines 18–20why, one step back18 grep -v '^[[:blank:]]*#' "$dir/common.sh" # remove code comments in common.sh19 sed -n '/^#----END INCLUDE/,$p' "$1"20 } > "$1.part"bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
line 21why, one step back21fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
line 22why, one step back22 mv -f "$1.part" "$1"bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 23–24why, one step back23}24fish: Completion script rewrite (SHIFT-TAB)bitraidbefore adoption23164c2
lines 25–28why, one step back25update "$dir/completion.bash"26update "$dir/completion.zsh"27update "$dir/key-bindings.bash"28update "$dir/key-bindings.zsh"bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd
lines 29–68why, one step back2930# Check if --check is in ARGV31check=032rest=()33for arg in "$@"; do34 case $arg in35 --check) check=1 ;;36 *) rest+=("$arg") ;;37 esac38done3940fmt() {41 if ! grep -q "^#----BEGIN shfmt" "$1"; then42 if [[ $check == 1 ]]; then43 shfmt -d "$1"44 return $?45 else46 shfmt -w "$1"47 fi48 else49 {50 sed -n '1,/^#----BEGIN shfmt/p' "$1" | sed '$d'51 sed -n '/^#----BEGIN shfmt/,/^#----END shfmt/p' "$1" | shfmt --filename "$1"52 sed -n '/^#----END shfmt/,$p' "$1" | sed '1d'53 } > "$1.part"5455 if [[ $check == 1 ]]; then56 diff -q "$1" "$1.part"57 ret=$?58 rm -f "$1.part"59 return $ret60 fi6162 mv -f "$1.part" "$1"63 fi64}6566for file in "${rest[@]}"; do67 fmt "$file" || exit $?68done