Skip to content

Commit

Permalink
contrib: add "histdb"
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Jan 31, 2023
1 parent e3cdb9d commit 44d9e10
Show file tree
Hide file tree
Showing 13 changed files with 686 additions and 50 deletions.
1 change: 1 addition & 0 deletions README-ja_JP.md
Expand Up @@ -341,6 +341,7 @@ make INSDIR="$HOME/.local/share/blesh" install
- `blerc` 設定ファイル (`~/.blerc` または `~/.config/blesh/init.sh`) があれば削除します。
- `ble.sh` をインストールしたディレクトリを削除します。
- キャッシュディレクトリ `~/.cache/blesh` が生成されていればそれを削除します。
- 状態ディレクトリ `~/.cache/blesh` が生成されていればそれを削除します。
- 一時ディレクトリ `/tmp/blesh` が生成されていればそれを削除します。これは `/tmp` の内容が自動的にクリアされないシステムで必要です。

# 2 基本設定
Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -321,6 +321,7 @@ Basically you can simply delete the installed directory and the settings that th
- Remove `blerc` files (`~/.blerc` or `~/.config/blesh/init.sh`) if any.
- Remove the installed directory.
- Remove the cache directory `~/.cache/blesh` if any.
- Remove the state directory `~/.local/state/blesh` if any.
- Remove the temporary directory `/tmp/blesh` if any [ Only needed when your system does not automatically clears `/tmp` ].

# 2 Basic settings
Expand Down
98 changes: 94 additions & 4 deletions ble.pp
Expand Up @@ -257,7 +257,7 @@ function ble/base/adjust-builtin-wrappers/.assign {
if [[ ${_ble_util_assign_base-} ]]; then
local _ble_local_tmpfile; ble/util/assign/.mktmp
builtin eval -- "$1" >| "$_ble_local_tmpfile"
IFS= builtin read -r -d '' defs < "$_ble_local_tmpfile"
IFS= builtin read "${_ble_bash_tmout_wa[@]}" -r -d '' defs < "$_ble_local_tmpfile"
ble/util/assign/.rmtmp
else
defs=$(builtin eval -- "$1")
Expand Down Expand Up @@ -965,11 +965,21 @@ function ble/init/check-environment {

if [[ ! $USER ]]; then
ble/util/print "ble.sh: insane environment: \$USER is empty." >&2
if type id &>/dev/null; then
export USER=$(id -un)
if USER=$(id -un) && [[ $USER ]]; then
export USER
ble/util/print "ble.sh: modified USER=$USER" >&2
fi
fi
_ble_base_env_USER=$USER

if [[ ! $HOSTNAME ]]; then
ble/util/print "ble.sh: suspicious environment: \$HOSTNAME is empty."
if HOSTNAME=$(uname -n 2>/dev/null) && [[ $HOSTNAME ]]; then
export HOSTNAME
ble/util/print "ble.sh: fixed HOSTNAME=$HOSTNAME" >&2
fi
fi
_ble_base_env_HOSTNAME=$HOSTNAME

# 暫定的な ble/bin/$cmd 設定
ble/bin/.default-utility-path "${_ble_init_posix_command_list[@]}"
Expand Down Expand Up @@ -1494,6 +1504,63 @@ function ble/base/migrate-cache-directory {
fi
ble/base/migrate-cache-directory

##
## @var _ble_base_state
##
## 環境毎の初期化ファイルを格納するディレクトリ。以下の手順で決定する。
##
## 1. ${XDG_STATE_HOME:=$HOME/.state} (存在しなくても強制的に作成) の下に blesh を作成して使う。
## 2. (1. に失敗した時) $_ble_base/state.d/$UID を使う。
##
function ble/base/initialize-state-directory/.xdg {
local state_dir=${XDG_STATE_HOME:-$HOME/.local/state}
if [[ -e $state_dir || -L $state_dir ]]; then
if [[ ! -d $state_dir ]]; then
if [[ $XDG_STATE_HOME ]]; then
ble/util/print "ble.sh: XDG_STATE_HOME='$XDG_STATE_HOME' is not a directory." >&2
else
ble/util/print "ble.sh: '$state_dir' is not a directory." >&2
fi
return 1
fi
if ! [[ -r $state_dir && -w $state_dir && -x $state_dir ]]; then
if [[ $XDG_STATE_HOME ]]; then
ble/util/print "ble.sh: XDG_STATE_HOME='$XDG_STATE_HOME' doesn't have a proper permission." >&2
else
ble/util/print "ble.sh: '$state_dir' doesn't have a proper permission." >&2
fi
return 1
fi
fi

ble/base/.create-user-directory _ble_base_state "$state_dir/blesh"
}
function ble/base/initialize-state-directory {
ble/base/initialize-state-directory/.xdg && return 0

# fallback
local state_dir=$_ble_base/state.d
if [[ ! -d $state_dir ]]; then
ble/bin/mkdir -p "$state_dir" || return 1
ble/bin/chmod a+rwxt "$state_dir" || return 1

# relocate an old state directory if any
local old_state_dir=$_ble_base/state
if [[ -d $old_state_dir && ! -h $old_state_dir ]]; then
mv "$old_state_dir" "$state_dir/$UID"
ln -s "$state_dir/$UID" "$old_state_dir"
fi
fi
ble/util/print "ble.sh: using the non-standard position of the state directory: '$state_dir/$UID'" >&2
ble/base/.create-user-directory _ble_base_state "$state_dir/$UID"
}
if ! ble/base/initialize-state-directory; then
ble/util/print "ble.sh: failed to initialize \$_ble_base_state." 1>&2
builtin unset -v _ble_bash BLE_VERSION BLE_VERSINFO
ble/init/clean-up 2>/dev/null # set -x 対策 #D0930
return 1
fi


function ble/base/print-usage-for-no-argument-command {
local name=${FUNCNAME[1]} desc=$1; shift
Expand Down Expand Up @@ -1775,6 +1842,27 @@ function ble-update {
ble/builtin/trap/install-hook ERR inactive
ble/builtin/trap/install-hook RETURN inactive

# @var _ble_base_session
# @var BLE_SESSION_ID
function ble/base/initialize-session {
[[ $_ble_base_session == */"$$" ]] && return 0

local start_time=
if ((_ble_bash>=50000)); then
start_time=${EPOCHREALTIME//[!0-9]}
elif ((_ble_bash>=40200)); then
printf -v start_time '%(%s)T'
((start_time*=1000000))
else
ble/util/assign start_time 'ble/bin/date +%s'
fi
((start_time-=SECONDS*1000000))

_ble_base_session=${start_time::${#start_time}-6}.${start_time:${#start_time}-6}/$$
BLE_SESSION_ID=$_ble_base_session
}
ble/base/initialize-session

#%x inc.r|@|src/decode|
#%x inc.r|@|src/color|
#%x inc.r|@|src/canvas|
Expand Down Expand Up @@ -1844,7 +1932,9 @@ function ble/dispatch {
(version|--version) ble/util/print "ble.sh, version $BLE_VERSION (noarch)" ;;
(check|--test) ble/base/sub:test "$@" ;;
(*)
if ble/is-function ble/bin/ble; then
if ble/string#match "$cmd" '^[a-z0-9]+$' && ble/is-function "ble-$cmd"; then
"ble-$cmd" "$@"
elif ble/is-function ble/bin/ble; then
ble/bin/ble "$cmd" "$@"
else
ble/util/print "ble (ble.sh): unrecognized subcommand '$cmd'." >&2
Expand Down
2 changes: 1 addition & 1 deletion contrib
Submodule contrib updated 2 files
+2 −1 colorglass.bash
+294 −0 histdb.bash
4 changes: 3 additions & 1 deletion docs/ChangeLog.md
Expand Up @@ -116,7 +116,8 @@
- edit (`magic-space`): support `bleopt edit_magic_expand=...:alias` (requested by telometto) `#D1912` 63da2ac
- auto-complete: cancel auto-complete for `magic-space` `#D1913` 01b4f67
- complete: support ambiguous completion for command paths `#D1922` 8a716ad
- complete: preserve original path segments as long as possible `#D1923` `#D1924` xxxxxxx
- complete: preserve original path segments as long as possible `#D1923` `#D1924` e3cdb9d
- main: support `BLE_SESSION_ID` and `BLE_COMMAND_ID` `#D1925` xxxxxxx

## Changes

Expand Down Expand Up @@ -529,6 +530,7 @@
- colorglass: add color filter `#D1902` 88e74cc
- colorglass: add `bleopt colorglass_{saturation,brightness}` (motivated by auwsom) `#D1906` 40625ac
- fzf-key-bindings: fix a problem that `modifyOtherKeys` is not reflected (reported by SuperSandro2000) `#D1908` 486564a
- add `histdb` `#D1925` xxxxxxx

<!---------------------------------------------------------------------------->
# ble-0.4.0-devel2
Expand Down
2 changes: 1 addition & 1 deletion lib/core-complete.sh
Expand Up @@ -7955,7 +7955,7 @@ function ble/widget/auto_complete/self-insert/.is-magic-space {
function ble/widget/auto_complete/self-insert {
if ble/widget/auto_complete/self-insert/.is-magic-space; then
ble/widget/auto_complete/cancel-default
return $?
return "$?"
fi

local code; ble/widget/self-insert/.get-code
Expand Down
3 changes: 2 additions & 1 deletion lib/init-msleep.sh
Expand Up @@ -18,7 +18,8 @@ function ble/util/msleep/.load-compiled-builtin {
local basename=$_ble_edit_io_fname2
local fname_buff=$basename.buff

local builtin_path=$_ble_base_cache/init-msleep.$_ble_bash.$HOSTNAME.so
local hostname=${HOSTNAME:-$_ble_base_env_HOSTNAME}
local builtin_path=$_ble_base_cache/init-msleep.$_ble_bash.$hostname.so
local builtin_runpath=$_ble_base_run/$$.init-msleep.so
ble/util/msleep/.load-compiled-builtin/compile "$builtin_path" &&
ble/bin/cp "$builtin_path" "$builtin_runpath" || return 1
Expand Down
2 changes: 1 addition & 1 deletion lib/vim-airline.sh
Expand Up @@ -133,7 +133,7 @@ function ble/lib/vim-airline/convert-theme/.setface {
function ble/lib/vim-airline/convert-theme {
local file=$1
sed -n 's/let s:airline_\([a-zA-Z_0-9]\{1,\}\)[^[:alnum:]]\{1,\}\(\#[0-9a-fA-F]\{6\}\)[^[:alnum:]]\{1,\}\(\#[0-9a-fA-F]\{6\}\).*/\1 \2 \3/p' "$file" |
while builtin read -r face fg bg; do
while builtin read "${_ble_bash_tmout_wa[@]}" -r face fg bg; do
ble/lib/vim-airline/convert-theme/.setface "$face" "$fg" "$bg"
done
}
Expand Down
2 changes: 1 addition & 1 deletion make/debug.leakvar.exclude-list.txt
Expand Up @@ -124,7 +124,6 @@
^TEXMFHOME=
^TIME_STYLE=
^USER=
^WINDOW=
^XDG_RUNTIME_DIR=
^XDG_SESSION_CLASS=
^XDG_SESSION_ID=
Expand Down Expand Up @@ -155,6 +154,7 @@
^SSH_CONNECTION=
^SSH_TTY=
^STY=
^WINDOW=
--------------------------------------------------------------------------------
# bash-completion
^_xspecs=
Expand Down
2 changes: 2 additions & 0 deletions make_command.sh
Expand Up @@ -1172,6 +1172,7 @@ function sub:scan/bash502-patsub_replacement {
grc --color '\$\{[[:alnum:]_]+(\[[^][]*\])?//?([^{}]|\{[^{}]*\})+/[^{}"'\'']*([&$]|\\)' --exclude=./test |
sed -E 'h;s/'"$esc"'//g;s/^[^:]*:[0-9]+:[[:space:]]*//
\Z//?\$q/\$Q\}Zd
\Z//?\$q/\$qq\}Zd
\Z//?\$__ble_q/\$__ble_Q\}Zd
\Z//?\$_ble_local_q/\$_ble_local_Q\}Zd
\Z/\$\(\([^()]+\)\)\}Zd
Expand Down Expand Up @@ -1297,6 +1298,7 @@ function sub:scan/word-splitting-number {
\Z\$\{#[a-zA-Z_0-9]+\}[<>?&]Zd
\Z \$\{\#[a-zA-Z_0-9]+\[@\]\} -gt 0 \]\]Zd
\Zcase \$\? inZd
\Zcase \$\(\(.*\)\) inZd
g'
}

Expand Down

0 comments on commit 44d9e10

Please sign in to comment.