From 0bc26602085fd68aaf32941972e34dc0a370c38b Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Sat, 15 May 2021 00:13:56 +0900 Subject: [PATCH] main (ble-update): support package updates and "sudo" updates --- GNUmakefile | 48 +++++++++++---- README-ja_JP.md | 4 ++ README.md | 4 ++ ble.pp | 147 ++++++++++++++++++++++++++++++++++----------- make_command.sh | 2 + memo/ChangeLog.md | 13 ++-- note.txt | 148 ++++++++++++++++++++++++++++++++++++++++++++++ src/util.sh | 34 ++++++++--- 8 files changed, 341 insertions(+), 59 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index 94725a68..b2607ea6 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -85,6 +85,17 @@ $(OUTDIR)/lib/init-msys1.sh: lib/init-msys1.sh lib/init-msys1-helper.c | $(OUTDI #$(OUTDIR)/lib/init-msleep.sh: lib/init-msleep.sh lib/init-msleep.c | $(OUTDIR)/lib # $(MWGPP) $< > $@ +#------------------------------------------------------------------------------ +# documents + +outdirs += $(OUTDIR)/doc +outfiles-doc += $(OUTDIR)/doc/README.md +outfiles-doc += $(OUTDIR)/doc/README-ja_JP.md +outfiles-doc += $(OUTDIR)/doc/CONTRIBUTING.md +outfiles-doc += $(OUTDIR)/doc/LICENSE.md +$(OUTDIR)/doc/%: % | $(OUTDIR)/doc + cp -p $< $@ + #------------------------------------------------------------------------------ # contrib @@ -105,7 +116,7 @@ $(OUTDIR)/contrib/%.bash: contrib/%.bash | contrib/.git $(OUTDIR)/contrib $(outdirs): mkdir -p $@ -build: contrib/.git $(outfiles) +build: contrib/.git $(outfiles) $(outfiles-doc) .PHONY: build all: build @@ -113,22 +124,35 @@ all: build #------------------------------------------------------------------------------ # target "install" -ifneq ($(filter-out %/,$(DESTDIR)),) - DESTDIR := $(DESTDIR)/ -endif - -ifneq ($(DESTDIR)$(PREFIX),) - DATA_HOME := $(DESTDIR)$(PREFIX)/share -else ifneq ($(XDG_DATA_HOME),) - DATA_HOME := $(XDG_DATA_HOME) +ifneq ($(INSDIR),) + ifeq ($(INSDIR_DOC),) + INSDIR_DOC := $(INSDIR)/doc + endif else - DATA_HOME := $(HOME)/.local/share + ifneq ($(filter-out %/,$(DESTDIR)),) + DESTDIR := $(DESTDIR)/ + endif + + ifneq ($(DESTDIR)$(PREFIX),) + DATA_HOME := $(DESTDIR)$(PREFIX)/share + else ifneq ($(XDG_DATA_HOME),) + DATA_HOME := $(XDG_DATA_HOME) + else + DATA_HOME := $(HOME)/.local/share + endif + + INSDIR = $(DATA_HOME)/blesh + INSDIR_DOC = $(DATA_HOME)/doc/blesh endif -INSDIR = $(DATA_HOME)/blesh -install: $(outfiles:$(OUTDIR)/%=$(INSDIR)/%) $(INSDIR)/cache.d $(INSDIR)/tmp +install: \ + $(outfiles:$(OUTDIR)/%=$(INSDIR)/%) \ + $(outfiles-doc:$(OUTDIR)/doc/%=$(INSDIR_DOC)/%) \ + $(INSDIR)/cache.d $(INSDIR)/tmp $(INSDIR)/%: $(OUTDIR)/% bash make_command.sh install "$<" "$@" +$(INSDIR_DOC)/%: $(OUTDIR)/doc/% + bash make_command.sh install "$<" "$@" $(INSDIR)/cache.d $(INSDIR)/tmp: mkdir -p $@ && chmod a+rwxt $@ .PHONY: install diff --git a/README-ja_JP.md b/README-ja_JP.md index 298f7007..41ccfbf7 100644 --- a/README-ja_JP.md +++ b/README-ja_JP.md @@ -44,6 +44,10 @@ git clone --recursive https://github.com/akinomyoga/ble.sh.git make -C ble.sh install DESTDIR=/tmp/blesh-package PREFIX=/usr/local ``` +パッケージ管理システムを通じて `ble.sh` をインストールする事もできます (現在 AUR のみ)。 + +- [AUR (Arch Linux)](https://github.com/akinomyoga/ble.sh/wiki/Manual-A1-Installation#user-content-AUR) `blesh-git` (devel), `blesh` (stable 0.3.3) maintained by [`@oc1024`](https://github.com/oc1024) + ## 機能概要 - **構文着色**: `fish` や `zsh-syntax-highlighting` のような文法構造に従った着色を行います。 diff --git a/README.md b/README.md index fb00bd02..8e6b9b83 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,10 @@ git clone --recursive https://github.com/akinomyoga/ble.sh.git make -C ble.sh install DESTDIR=/tmp/blesh-package PREFIX=/usr/local ``` +You may also install `ble.sh` through package-management systems (currently only AUR): + +- [AUR (Arch Linux)](https://github.com/akinomyoga/ble.sh/wiki/Manual-A1-Installation#user-content-AUR) `blesh-git` (devel), `blesh` (stable 0.3.3) maintained by [`@oc1024`](https://github.com/oc1024) + ## Features - **Syntax highlighting**: Highlight command lines input by users as in `fish` and `zsh-syntax-highlighting`. diff --git a/ble.pp b/ble.pp index a6d0a2dd..57be3460 100644 --- a/ble.pp +++ b/ble.pp @@ -50,16 +50,16 @@ { #%$ echo "_ble_init_version=$FULLVER+$(git show -s --format=%h)" _ble_init_exit= - _ble_init_test= + _ble_init_command= for _ble_init_arg; do case $_ble_init_arg in --version) - _ble_init_exit=1 - echo "ble.sh -- Bash Line Editor (ble-$_ble_init_version)" ;; + _ble_init_exit=0 + echo "ble.sh (Bash Line Editor), version $_ble_init_version" ;; --help) - _ble_init_exit=1 + _ble_init_exit=0 printf '%s\n' \ - "# ble.sh -- Bash Line Editor (ble-$_ble_init_version)" \ + "# ble.sh (Bash Line Editor), version $_ble_init_version" \ 'usage: source ble.sh [OPTION...]' \ '' \ 'OPTION' \ @@ -70,6 +70,10 @@ ' Show version and exit' \ ' --test' \ ' Run test and exit' \ + ' --update' \ + ' Run test and exit' \ + ' --clear-cache' \ + ' Run test and exit' \ '' \ ' --rcfile=BLERC' \ ' --init-file=BLERC' \ @@ -93,16 +97,17 @@ ' --debug-bash-output' \ ' Internal settings for debugging' \ '' ;; - --test) - _ble_init_test=1 ;; + --test) _ble_init_command=test ;; + --update) _ble_init_command=update ;; + --clear-cache) _ble_init_command=clear-cache ;; esac done if [ -n "$_ble_init_exit" ]; then unset _ble_init_version unset _ble_init_arg unset _ble_init_exit - unset _ble_init_test - return 1 2>/dev/null || exit 1 + unset _ble_init_command + return 0 2>/dev/null || exit 0 fi } 2>/dev/null # set -x 対策 #D0930 @@ -119,7 +124,7 @@ return 1 2>/dev/null || exit 1 fi 3>&2 >/dev/null 2>&1 # set -x 対策 #D0930 -if [[ $- != *i* && ! $_ble_init_test ]]; then +if [[ $- != *i* && ! $_ble_init_command ]]; then { ((${#BASH_SOURCE[@]})) && [[ ${BASH_SOURCE[${#BASH_SOURCE[@]}-1]} == *bashrc ]]; } || builtin echo "ble.sh: This is not an interactive session." >&3 return 1 2>/dev/null || builtin exit 1 @@ -309,7 +314,7 @@ function ble/base/reinforce-bash-options { builtin bind -m emacs '"\C-?": backward-delete-char' fi -if [[ ! -o emacs && ! -o vi && ! $_ble_init_test ]]; then +if [[ ! -o emacs && ! -o vi && ! $_ble_init_command ]]; then builtin echo "ble.sh: ble.sh is not intended to be used with the line-editing mode disabled (--noediting)." >&2 ble/base/restore-bash-options ble/base/restore-builtin-wrappers @@ -790,14 +795,63 @@ function ble/base/print-usage-for-no-argument-command { return 0 } function ble-reload { source "$_ble_base/ble.sh"; } + #%$ pwd=$(pwd) q=\' Q="'\''" bash -c 'echo "_ble_base_repository=$q${pwd//$q/$Q}$q"' #%$ echo "_ble_base_branch=$(git rev-parse --abbrev-ref HEAD)" +function ble-update/.check-install-directory-ownership { + if [[ ! -O $_ble_base ]]; then + ble/uti/print 'ble-update: install directory is owned by another user:' >&2 + ls -ld "$_ble_base" + return 1 + elif [[ ! -r $_ble_base || ! -w $_ble_base || ! -x $_ble_base ]]; then + ble/uti/print 'ble-update: install directory permission denied:' >&2 + ls -ld "$_ble_base" + return 1 + fi +} +function ble-update/.make { + local sudo= + if [[ $1 == --sudo ]]; then + sudo=1 + shift + fi + + if ! "$MAKE" -q "$@"; then + if [[ $sudo ]]; then + sudo "$MAKE" "$@" + else + "$MAKE" "$@" + fi + else + # インストール先に更新がなくても現在の session でロードされている ble.sh が + # 古いかもしれないのでチェックしてリロードする。 + return 6 + fi +} +function ble-update/.reload { + if [[ $- == *i* && $_ble_attached ]]; then + ble-reload + fi +} function ble-update { if (($#)); then ble/base/print-usage-for-no-argument-command 'Update and reload ble.sh.' "$@" return "$?" fi + if [[ $_ble_base_package_type ]] && ble/is-function ble/base/package:"$_ble_base_package_type"/update; then + ble/util/print "ble-update: delegate to '$_ble_base_package_type' package manager..." >&2 + ble/base/package:"$_ble_base_package_type"/update; local ext=$? + if ((ext==125)); then + ble/util/print 'ble-update: fallback to the default update process.' >&2 + elif [[ $ext -eq 0 || $ext -eq 6 && $_ble_base/ble.sh -nt $_ble_base_run/$$.load ]]; then + ble-update/.reload + return $? + else + return "$ext" + fi + fi + # check make local MAKE= if type gmake &>/dev/null; then @@ -819,33 +873,52 @@ function ble-update { return 1 fi + local insdir_doc=$_ble_base/doc + [[ ! -d $insdir_doc && -d ${_ble_base%/*}/doc/blesh ]] && + insdir_doc=${_ble_base%/*}/doc/blesh + if [[ $_ble_base_repository && $_ble_base_repository != release:* ]]; then - if [[ -e $_ble_base_repository/.git ]]; then + if [[ ! -e $_ble_base_repository/.git ]]; then + ble/util/print "ble-update: git repository not found at '$_ble_base_repository'." >&2 + elif [[ ! -O $_ble_base_repository ]]; then + ble/util/print "ble-update: git repository is owned by another user:" >&2 + ls -ld "$_ble_base_repository" + elif [[ ! -r $_ble_base_repository || ! -w $_ble_base_repository || ! -x $_ble_base_repository ]]; then + ble/util/print 'ble-update: git repository permission denied:' >&2 + ls -ld "$_ble_base_repository" + else ( ble/util/print "cd into $_ble_base_repository..." >&2 && builtin cd "$_ble_base_repository" && git pull && git submodule update --recursive --remote && - { ! "$MAKE" -q || builtin exit 6; } && "$MAKE" all && - if [[ $_ble_base != "$_ble_base_repository"/out ]]; then - "$MAKE" INSDIR="$_ble_base" install + if [[ $_ble_base == "$_ble_base_repository"/out ]]; then + ble-update/.make all + elif ((EUID!=0)) && ! ble-update/.check-install-directory-ownership; then + ble-update/.make all + ble-update/.make --sudo INSDIR="$_ble_base" INSDIR_DOC="$insdir_doc" install + else + ble-update/.make INSDIR="$_ble_base" INSDIR_DOC="$insdir_doc" install fi ); local ext=$? - if ((ext==6)); then - [[ $_ble_base/ble.sh -nt $_ble_base_run/$$.load ]] && ble-reload - return 0 + if [[ $ext -eq 0 || $ext -eq 6 && $_ble_base/ble.sh -nt $_ble_base_run/$$.load ]]; then + ble-update/.reload + return $? fi - ((ext==0)) && ble-reload return "$ext" fi - - ble/util/print 'ble-update: git repository not found' >&2 fi - - if [[ $_ble_base_branch ]]; then - # release version - local branch=$_ble_base_branch + + if ((EUID!=0)) && ! ble-update/.check-install-directory-ownership; then + # _ble_base が自分の物でない時は sudo でやり直す + sudo "$BASH" "$_ble_base/ble.sh" --update && + ble-update/.reload + return $? + else + # _ble_base/src 内部に clone して make install + local branch=${_ble_base_branch:-master} ( ble/bin/mkdir -p "$_ble_base/src" && builtin cd "$_ble_base/src" && git clone --recursive --depth 1 https://github.com/akinomyoga/ble.sh "$_ble_base/src/ble.sh" -b "$branch" && - builtin cd ble.sh && "$MAKE" all && "$MAKE" INSDIR="$_ble_base" install ) && - ble-reload + builtin cd ble.sh && "$MAKE" all && + "$MAKE" INSDIR="$_ble_base" INSDIR_DOC="$insdir_doc" install ) && + ble-update/.reload return "$?" fi return 1 @@ -933,7 +1006,7 @@ function ble/dispatch { (palette) ble-color-show "$@" ;; (help|--help) ble/dispatch/.help "$@" ;; (version|--version) ble/util/print "ble.sh, version $BLE_VERSION (noarch)" ;; - (check|--test) ble/base/test "$@" ;; + (check|--test) ble/base/sub:test "$@" ;; (*) if ble/is-function ble/bin/ble; then ble/bin/ble "$cmd" "$@" @@ -1213,11 +1286,13 @@ function ble/base/process-blesh-arguments { } function ble/base/initialize/.clean-up { + local ext=$? # preserve exit status + # 一時グローバル変数消去 builtin unset -v _ble_init_version builtin unset -v _ble_init_arg builtin unset -v _ble_init_exit - builtin unset -v _ble_init_test + builtin unset -v _ble_init_command # 状態復元 if [[ $_ble_init_original_IFS_set ]]; then @@ -1233,9 +1308,10 @@ function ble/base/initialize/.clean-up { ble/base/restore-builtin-wrappers builtin eval -- "$_ble_bash_FUNCNEST_restore" fi + return "$ext" } -function ble/base/test { +function ble/base/sub:test { local error= if ((!_ble_make_command_check_count)); then echo "MACHTYPE: $MACHTYPE" @@ -1247,11 +1323,16 @@ function ble/base/test { source "$_ble_base"/lib/test-canvas.sh || error=1 [[ ! $error ]] } +function ble/base/sub:update { ble-update; } +function ble/base/sub:clear-cache { + (shopt -u failglob; ble/bin/rm -rf "$_ble_base_cache"/*) +} -if [[ $_ble_init_test ]]; then - if ! ble/base/test; then +ble-import -f lib/_package +if [[ $_ble_init_command ]]; then + if ! ble/base/sub:"$_ble_init_command"; then ble/base/initialize/.clean-up 2>/dev/null # set -x 対策 #D0930 - { return 1 || exit 1; } 2>/dev/null # set -x 対策 #D0930 + { return $? || exit $?; } 2>/dev/null # set -x 対策 #D0930 fi else ble/base/process-blesh-arguments "$@" diff --git a/make_command.sh b/make_command.sh index 524f844c..da9c28bb 100755 --- a/make_command.sh +++ b/make_command.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +umask 022 + function mkd { [[ -d $1 ]] || mkdir -p "$1" } diff --git a/memo/ChangeLog.md b/memo/ChangeLog.md index 356b8eb9..82b7c21f 100644 --- a/memo/ChangeLog.md +++ b/memo/ChangeLog.md @@ -29,8 +29,9 @@ - edit: support `nsearch` options (motivated by Alyetama, rashil2000, carv-silva) `#D1517` 9125795 - syntax: support the deprecated redirection `>& file` `#D1539` b9b0de4 - complete: complete file descriptors and heredoc words after redirections `#D1539` b9b0de4 -- main: support `blehook ATTACH DETACH`, `BLE_ONLOAD`, `BLE_ATTACHED` `#D1543` 0000000 -- main: support `ble` `#D1544` 0000000 +- main: support `blehook ATTACH DETACH`, `BLE_ONLOAD`, `BLE_ATTACHED` `#D1543` 750ca38 +- main: support `ble` `#D1544` 750ca38 +- main (`ble-update`): support package updates and `sudo` updates (motivated by huresche, oc1024) `#D1548` 0000000 ## Changes @@ -61,10 +62,10 @@ - syntax (`ble/syntax:bash/simple-word/eval`): optimize large array passing (motivated by timjrd) `#D1522` c89aa23 - main: accept non-regular files as `blerc` and add option `--norc` `#D1530` 7244e2f - prompt: let `stderr` pass through to tty in evaluating `PS0` (reported by tycho-kirchner) `#D1541` 24a88ce -- prompt: adjust behavior of `LINENO` and prompt sequence `\#` (reported by tycho-kirchner) `#D1542` 0000000 -- edit (`widget:display-shell-version`): include `ble.sh` version `#D1545` 0000000 -- complete (`ble-sabbrev`): support colored output `#D1546` 0000000 -- complete (`ble-bind`): support colored output `#D1547` 0000000 +- prompt: adjust behavior of `LINENO` and prompt sequence `\#` (reported by tycho-kirchner) `#D1542` 8b0257e +- edit (`widget:display-shell-version`): include `ble.sh` version `#D1545` 750ca38 +- complete (`ble-sabbrev`): support colored output `#D1546` 750ca38 +- complete (`ble-bind`): support colored output `#D1547` 750ca38 ## Fixes diff --git a/note.txt b/note.txt index e667e61f..27f0b8ea 100644 --- a/note.txt +++ b/note.txt @@ -805,6 +805,13 @@ bash_tips Memo ------------------------------------------------------------------------------- +2021-05-15 + + * PKGBUILD の説明は此処にある [#M0020] + https://wiki.archlinux.org/title/VCS_package_guidelines + https://wiki.archlinux.jp/index.php/PKGBUILD + https://wiki.archlinux.jp/index.php/%E3%83%91%E3%83%83%E3%82%B1%E3%83%BC%E3%82%B8%E3%81%AE%E4%BD%9C%E6%88%90#.E9.96.A2.E6.95.B0_pkgver.28.29 + 2021-05-03 * awk の互換性に関する注意点 [#M0019] @@ -1360,6 +1367,49 @@ bash_tips 0.5 ControlPanel/TUI Framework 0.4 progcolor +2021-05-15 + + * README: 様々な機能へのリンクを貼った方が良いのではないかという事 + +2021-05-13 + + * vi_imap が empty と表示されるとの事 + https://github.com/akinomyoga/ble.sh/issues/109 + + "ble.sh: The keymap 'vi_imap' is empty." というエラーメッセージが出るとの事 + だが他には何もメッセージは出ないのだろうか。試しに keymap.vi を空にしてロー + ドしてみると…再現した。 + + * bash ble.sh --clear-cache オプションを実装した方が良い。 + + * ファイルが存在するかどうかのチェックをしている箇所は、全て有限の大きさを持っているかどうかを確認した方が良い。 + + * 空の keymap になっていたらキャッシュ無しで初期化し直す機能を付けた方が良いかもしれない。 + + * ssh -option の後の補完が固まる + https://github.com/akinomyoga/ble.sh/issues/98 + + $ alias ssh='TERM=xterm ssh' + + で再現するとの情報を得た。他に man -w が現れたり消えたりするという情報も。 + つまり、一つの man -w が 100% になっているのではなくて man -w が繰り返しルー + プで呼び出されている? また、cache dir に大量のファイルができているという話 + も。つまり、ble/util/assign で無限ループを起こしている可能性がある。 + + + $ complete -r + $ source ~/.fzf.bash + $ TERM=xterm ssh -w[TAB] + + TERM=xterm ssh -bash: 一致しません: /home/murase/.ssh/config.d/* + + * + + 1>&$fd- は使えない + 1>&./- もエラーになる + + もっとちゃんと調べる必要がある + 2021-05-09 * Fedora の package にするには結構面倒な手続きが要りそうな感じである。 @@ -4377,6 +4427,104 @@ bash_tips Done (実装ログ) ------------------------------------------------------------------------------- +2021-05-15 + + * package: AUR package (suggested by huresche, help by oc1024) [#D1548] + https://github.com/akinomyoga/ble.sh/issues/108 + Ref #M0020 PKGUBUILD の書き方 + + AUR の PKGBUILD の提案を受けた。PKGBUILD の内容を確認してみる。 + + | > arch=('x86_64') + | + | arch=('any') + | + | > makedepends=('git') + | + | makedepends=('git' 'gawk') + | + | > pkgver() { + | > cd "${srcdir}/${_pkgname}" + | > printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)" + | > } + | + | > install -Dm644 ./note.txt "${pkgdir}/usr/share/doc/${_pkgname}/note.txt" + | + | `note.txt` is just a private note but not a part of the documentation. + + というか既にパッケージにしている人がいる。 + https://aur.archlinux.org/packages/blesh/ + https://aur.archlinux.org/packages/blesh-git/ + + PKGBUILD の説明は此処にある + https://wiki.archlinux.org/title/VCS_package_guidelines + https://wiki.archlinux.jp/index.php/PKGBUILD + https://wiki.archlinux.jp/index.php/%E3%83%91%E3%83%83%E3%82%B1%E3%83%BC%E3%82%B8%E3%81%AE%E4%BD%9C%E6%88%90#.E9.96.A2.E6.95.B0_pkgver.28.29 + + * fixed: 自分で試しに install を実行してみた所 644 になっていない。うーん。 + 644 もしくは 755 になる様に umask 022 とした。 + + ble-update を実行すると何が起こるのだろうか。 + 取り敢えず複数の方法を組み合わせて対応するのが良い。 + + a /usr/* /opt/* etc であって、 + ファイルが存在するけれど書き込み権限がないという時には、 + sudo bash "$_ble_base/ble.sh" --update を実行する。 + sudo の存在チェックも一応する必要がある気がする。 + + (a) repository の書き込み権限がない場合と、(b) install 先の書き込み権限が + ない場合の二つがある。(c) それから repository が見つからなくて、install + 先の書き込み権限がない場合もある。(a) と (c) の場合には全体を sudo で実行 + し直せば良い。但し、(a) の場合には他のユーザーのディレクトリを sudo で更 + 新してしまうと変な事になるのでユーザーのチェックは必要である。権限昇格し + た後に [[ -O file ]] でチェックすれば良いのだろうか。取り敢えずその方針で + 行く。 + + この為に ble.sh --update に対応する必要がある。 + + そもそも勝手にアップデートして良いのだろうか。複数のユーザーが勝手にアップ + デートしたらどうなるのだろうか。と思ったが sudo 権限を持っているユーザーが + 勝手に物を実行するのが悪い。sudo を使ってインストールするのだからそれなりに + 他の人に気を遣うべきである。 + + b アップデート用のスクリプトを作って sticky bit を付けて無理やりアップデー + トを実行するという手もある。これは他のユーザーが同時にアップデートしたり + する危険性が高いし、管理者権限で現在の ble.sh の状態を管理する事が不可能 + になるので駄目。 + + c package manager が存在したらそれを使うという手を安易に提案されたが、それ + だと package manager を使わずにインストールされたのに勝手に package + manager 経由で再インストールされてしまうという事になりかねない。まあ、 + /usr/share に入っている時点で何らかの package manager を経由しているとい + う事は明らかなのだから、余り気にしなくて良いのかもしれない。 + + と思ったが現在の所は AUR ぐらいしか存在しない。そして AUR ではどの様にアッ + プデートしたら良いのかよく分からない。単に再インストールすれば良いのだろ + うか。或いは一旦削除してそれから入れるのだろうか。 + + d done: package maintainer の用意したファイルを source するという提案。これ + も確かに一つの手である。例えば lib/init-package.sh を使う。 + + * 名称について: もしくはlib/init-PACKAGE.bash 等の方が良いかもしれない。 + もしこれらのファイルが存在したらそれを source する事にする。PACKAGE と + 大文字にしていると PACKAGE の部分を package manager の名前に置き換える + のだと勘違いする人がいるかもしれない。やはり此処は init-package.sh にす + るべきだろうか。然しそうすると今度は他の普通のファイルとの見分けが付か + ない。或いは単に lib/package.sh とするか。或いは、lib/_package.bash と + いう形にするのが良いだろうか。 + + うーん。lib/_package.bash もしくは lib/_package.sh という事にする。内部 + で、ble/package/update なる関数を定義してもらう事にする。 + + * README にリンクを貼る。README が長くなるのも面倒だし、そもそも普段使って + いる人はコマンドを見なくても分かる筈。という訳で取り敢えずはパッケージ名 + だけ分かる様にしておく。 + + 一つ一つのコマンドについては Wiki にページを作る事にすれば良いだろうか。 + 然し、Wiki のページに跳ぶのも面倒である。それにリンクが沢山あるのも変な感 + じがする。或いは、リンクは Wiki のページだけに向かわせる事にする。パッケー + ジ名は単なる文字列とする。それが良い気がする。 + 2021-05-11 * bind: 無引数 ble-bind で現在の binding を表示。現在の binding の着色 [#D1547] diff --git a/src/util.sh b/src/util.sh index d208d303..d78158e2 100644 --- a/src/util.sh +++ b/src/util.sh @@ -3863,9 +3863,15 @@ function ble/util/import/finalize { done } ## @fn ble/util/import/.read-arguments args... -## @var[out] files flags +## @var[out] files +## @var[out] flags +## d delay +## h help +## f force +## E error function ble/util/import/.read-arguments { flags= files=() + local -a not_found=() while (($#)); do local arg=$1; shift if [[ $flags != *-* ]]; then @@ -3876,7 +3882,8 @@ function ble/util/import/.read-arguments { (--*) case $arg in (--delay) flags=d$flags ;; - (--help) flags=h$flags ;; + (--help) flags=h$flags ;; + (--force) flags=f$flags ;; (*) ble/util/print "ble-import: unrecognized option '$arg'" >&2 flags=E$flags ;; @@ -3887,7 +3894,7 @@ function ble/util/import/.read-arguments { for ((i=1;i<${#arg};i++)); do c=${arg:i:1} case $c in - (d) flags=$c$flags ;; + ([df]) flags=$c$flags ;; (*) ble/util/print "ble-import: unrecognized option '-$c'" >&2 flags=E$flags ;; @@ -3899,12 +3906,22 @@ function ble/util/import/.read-arguments { local ret if ! ble/util/import/search "$arg"; then - ble/util/print "ble-import: file '$arg' not found" >&2 - flags=E$flags + ble/array#push not_found "$arg" continue fi; local file=$ret ble/array#push files "$file" done + + # 存在しないファイルがあった時 + if [[ $flags != *f* ]] && ((${#not_found[@]})); then + local file + for file in "${not_found[@]}"; do + ble/util/print "ble-import: file '$file' not found" >&2 + done + flags=E$flags + fi + + return 0 } function ble/util/import { local file ext=0 @@ -3924,19 +3941,20 @@ function ble-import { if [[ $flags == *[Eh]* ]]; then [[ $flags == *E* ]] && ble/util/print { - ble/util/print 'usage: ble-import [-d] SCRIPTFILE...' + ble/util/print 'usage: ble-import [-df] SCRIPTFILE...' ble/util/print ' Search and source script files that have not yet been loaded.' } >&2 [[ $flags == *E* ]] && return 2 return 0 elif ((!${#files[@]})); then - ble/util/print 'ble-import: argument is not specified.' >&2 + [[ $flags == *f* ]] && return 0 + ble/util/print 'ble-import: files are not specified.' >&2 return 2 fi if [[ $flags == *d* ]] && ble/is-function ble/util/idle.push; then local ret - ble/string#quote-command ble-import "${files[@]}" + ble/string#quote-command ble/util/import "${files[@]}" ble/util/idle.push "$ret" return 0 fi