Skip to content

Commit

Permalink
history: disable the history file when "HISTFILE" is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Jul 9, 2022
1 parent 51cb735 commit 7153250
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
10 changes: 7 additions & 3 deletions keymap/vi.sh
Expand Up @@ -4920,12 +4920,16 @@ function ble/widget/vi-command/commandline.hook {
}

function ble/widget/vi-command:w {
local file=
if [[ $1 ]]; then
builtin history -a "$1"
local file=$1
else
file=$1
elif [[ ${HISTFILE-} ]]; then
builtin history -a
local file=${HISTFILE:-'~/.bash_history'}
file=$HISTFILE
else
ble/widget/vi-command/bell 'w: the history filename is empty or not specified'
return 1
fi
local wc
ble/util/assign wc 'wc "$file"'
Expand Down
9 changes: 4 additions & 5 deletions src/edit.sh
Expand Up @@ -4896,8 +4896,7 @@ function ble-edit/history/add/.command-history {
done
fi

local histfile=

local use_bash300wa=
if [[ $_ble_edit_history_loaded ]]; then
if [[ $HISTCONTROL ]]; then
local ignorespace ignoredups erasedups spec
Expand Down Expand Up @@ -4945,7 +4944,7 @@ function ble-edit/history/add/.command-history {

# _ble_bash<30100 の時は必ずここを通る。
# 初期化時に _ble_edit_history_loaded=1 になるので。
((_ble_bash<30100)) && histfile=${HISTFILE:-$HOME/.bash_history}
((_ble_bash<30100)) && use_bash300wa=1
else
if [[ $HISTCONTROL ]]; then
# 未だ履歴が初期化されていない場合は取り敢えず history -s に渡す。
Expand All @@ -4966,10 +4965,10 @@ function ble-edit/history/add/.command-history {
ble/util/sprintf cmd 'eval -- %q' "$cmd"
fi

if [[ $histfile ]]; then
if [[ $use_bash300wa ]]; then
# bash-3.1 workaround
local tmp=$_ble_base_run/$$.ble_edit_history_add.txt
builtin printf '%s\n' "$cmd" >> "$histfile"
[[ ${HISTFILE-} ]] && builtin printf '%s\n' "$cmd" >> "${HISTFILE-}"
builtin printf '%s\n' "$cmd" >| "$tmp"
builtin history -r "$tmp"
else
Expand Down

0 comments on commit 7153250

Please sign in to comment.