install.sh: -H|--hist|--history

This commit is contained in:
Dict Xiong 2023-01-31 20:49:15 +08:00
parent 063b15f4d5
commit a1c5d6deee
4 changed files with 42 additions and 2 deletions

View File

@ -109,6 +109,11 @@ prepare_config()
echo
}
append_hist()
{
"$DOTFILES/tools/append_zsh_hist.sh" "$@"
}
install_file_content()
{
fmt_note "installing file content ..."
@ -275,6 +280,7 @@ install()
# those that won't be uninstalled in the future
install_tmux_tpm
install_vim_vundle
if [[ -n "$DFS_HIST" ]]; then append_hist "$DFS_HIST"; fi
fmt_note "done installing!"
}
@ -296,18 +302,25 @@ echo "this is the dotfiles installer, version $(cd "$DOTFILES" && git describe -
FUNC=install
INSTALL_DEP=0
store_config=0
store_hist=0
for i in ${GOT_OPTS[@]}; do
if [[ "$store_config" == "1" ]]; then
store_config=0
DFS_CONFIGS+=("$i")
continue
fi
if [[ "$store_hist" == "1" ]]; then
store_hist=0
DFS_HIST=$i
continue
fi
case $i in
-i ) FUNC=install ;;
-r ) FUNC=uninstall ;;
-d|--dev ) export DFS_DEV=1; set -x ;;
-a|--auto ) INSTALL_DEP=1 ;;
-s|--secure ) export DFS_DEV=0 ;;
-H|--hist|--history ) store_hist=1 ;;
-x ) store_config=1 ;;
* ) fmt_fatal "unknown option \"$i\"" ;;
esac

View File

@ -41,4 +41,4 @@ route()
esac
}
route "$@"
route "${GOT_OPTS[@]}"

26
tools/append_zsh_hist.sh Executable file
View File

@ -0,0 +1,26 @@
#!/bin/bash
set -e
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
source "$THIS_DIR/common.sh"
zsh_hist_file="$HOME/.zsh_history"
do_append()
{
timestamp=$(date +%s)
while read -r line; do
echo ": $timestamp:0;$line" >> "$zsh_hist_file"
done
}
main()
{
key=$1
if [[ -z "$key" ]]; then
fmt_fatal "missing key"
fi
local url="https://pastebin.com/raw/$key"
curl -fsSL "$url" | do_append
}
main "${GOT_OPTS[@]}"

View File

@ -48,7 +48,8 @@ test `git rev-parse HEAD` = `curl -fsSL https://api.beardic.cn/get-var/dfs-commi
git reset --hard $DFS_VERSION
# then check install.sh
./install.sh -dx DFS_CI=1
./install.sh -dx DFS_CI=1 -H e153a2eL
grep -q "testhist 1" ~/.zsh_history
grep -q "DFS_CI=1" ~/.config/dotfiles/env
./install.sh -l -x DFS_CI=1
dfs version