~ane/web

a4efd514e7ab64f905444b7e3f547abc817a5f5d — Antoine Kalmbach 1 year, 11 months ago 87d4c5b
fix the script a little bit
1 files changed, 28 insertions(+), 1 deletions(-)

M _posts/2022-06-20-beenthere-donethat.md
M _posts/2022-06-20-beenthere-donethat.md => _posts/2022-06-20-beenthere-donethat.md +28 -1
@@ 49,7 49,8 @@ what's going to happen.

All possible with a couple of short bash functions!  `bt` stores data in a
simple tabulated list in your home directory, so it's nothing
complicated. Giving an argument to bt just saves that command directly, without prompting.
complicated. Giving an argument to bt just saves that command directly, without
prompting. You can have bt and dt too, just dump this into your `.bash_profile`:

``` shell
bt() {


@@ 69,6 70,32 @@ bt() {
    result="${CMD}\t${NAME}\t${LONG}\n"
    printf "$result" >> $DATA
}
bt() {
    if [[ -z "$1" ]]; then
        CMD=$(history 10 | fzf --header="Choose a command to save" --no-sort --tac | cut -d' ' -f 5-)
    else
        CMD=$1
    fi

    [[ -z "$CMD" ]] && echo "Aborted" && return 2
    echo "Saving \"${CMD}\"..."
    read -p "Name of command: " NAME
    [[ -z "$NAME" ]] && echo "No name given, aborting" && return 1
    LONG=$(read -p "Longer description (optional): ")

    if [[ ! -d "${HOME}/.config/btdt" ]]; then
        mkdir -p "${HOME}/.config/btdt"
    fi

    DATA="${BTDT_DATA:-${HOME}/.config/btdt/data}"

    if [[ ! -f $DATA ]]; then
        touch $DATA
    fi
    
    result="${CMD}\t${NAME}\t${LONG}\n"
    printf "$result" >> $DATA
}

dt() {
    local data="${BTDT_DATA:-${HOME}/.config/btdt/data}"