• 1 Post
  • 8 Comments
Joined 1 year ago
cake
Cake day: June 11th, 2023

help-circle


  • Just to share a perspective from erlang/elixir: pattern matching to filter for only happy-path inputs and the principle of “letting it fail” (when the inputs don’t match the expected shape) works really well in some paradigms (in this case, the actor model + OTP, erlang’s 9 9s of uptime, etc). In that kind of architecture you can really only care about the happy path, because the rest is malformed and can be thrown away without issue.




  • The simple and probably better answer is that you can just vim ~/.zsh_history and search for/delete the lines directly.

    Buuuuut! I wrote zsh command for doing exactly that a few years ago (in my dotfiles, but i’ve pasted it below as well):

    ################################################################################
    # Delete from history via fzf
    ################################################################################
    
    # https://superuser.com/questions/1316668/zsh-bash-delete-specific-lines-from-history
    function delete-command () {
      # Prevent the specified history line from being saved.
      local HISTORY_IGNORE="${(b)$(fc -ln $1 $1)}"
    
      # Write out the history to file, excluding lines that match `$HISTORY_IGNORE`.
      fc -W
    
      # Dispose of the current history and read the new history from file.
      fc -p "$HISTFILE" "$HISTSIZE" "$SAVEHIST"
    
      # TA-DA!
      print "Deleted '$HISTORY_IGNORE' from history."
    }
    
    function pick_from_history () {
      history | fzf --tac --tiebreak=index | perl -ne 'm/^\s*([0-9]+)/ and print "$1"'
    }
    
    function delete_from_history () {
      delete-command "$(pick_from_history)"
    }
    

    It uses fzf to filter and select a command to delete. It’s cool but might be slow b/c you’re doing it one at a time. It also may depend on your zsh config (i think the history command i’m using there comes from ohmyzsh, but i’m not too sure).