From a1c5d6deee4e185c09e0137dc4368f587ae8f9d0 Mon Sep 17 00:00:00 2001 From: Dict Xiong Date: Tue, 31 Jan 2023 20:49:15 +0800 Subject: [PATCH] install.sh: -H|--hist|--history --- install.sh | 13 +++++++++++++ scripts/pbin | 2 +- tools/append_zsh_hist.sh | 26 ++++++++++++++++++++++++++ tools/test.zsh | 3 ++- 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100755 tools/append_zsh_hist.sh diff --git a/install.sh b/install.sh index c84a3f3..5920bfe 100755 --- a/install.sh +++ b/install.sh @@ -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 diff --git a/scripts/pbin b/scripts/pbin index 017a079..3d410fb 100755 --- a/scripts/pbin +++ b/scripts/pbin @@ -41,4 +41,4 @@ route() esac } -route "$@" \ No newline at end of file +route "${GOT_OPTS[@]}" \ No newline at end of file diff --git a/tools/append_zsh_hist.sh b/tools/append_zsh_hist.sh new file mode 100755 index 0000000..12504c0 --- /dev/null +++ b/tools/append_zsh_hist.sh @@ -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[@]}" \ No newline at end of file diff --git a/tools/test.zsh b/tools/test.zsh index cbd75b7..4ac0fed 100644 --- a/tools/test.zsh +++ b/tools/test.zsh @@ -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