Hacker News new | ask | show | jobs
by buu700 1541 days ago
Currently, I'll append a comment to a frequently used command for easy searching from my history. For a simple example, I can access `git diff -w ; git diff -w --cached # gitdiff` by pressing Ctrl+R and typing `# gitd`.

For commands I use frequently or that are clunky to maintain as one-liners, I'll convert them into functions in my bashrc.

This seems like the best of both worlds in many ways, or at least is a great third option to have.

3 comments

From https://westurner.github.io/hnlog/#comment-20671184 ::

> I log shell commands with a script called usrlog.sh that creates [per-]$USER and per-virtualenv tab-delimited [$_USRLOG] logfiles with unique per-terminal-session identifiers [$_TERM_ID] and ISO8601 timestamps; so it's really easy to just grep for the apt/yum/dnf commands that I ran ad-hoc when I should've just taken a second to create an Ansible role with `ansible-galaxy init ansible-role-name ` and referenced that in a consolidated system playbook with a `when` clause. https://westurner.github.io/dotfiles/usrlog.html#usrlog

  stid \#tutorial; echo "$_TERM_ID"

  tail -n11 $_USRLOG
  ut -n11

  grep "$_TERM_ID" "$_USRLOG"
  usrlog_grep "$_TERM_ID"
  ug "$_TERM_ID"

  usrlog_grep_parse "$_TERM_ID"
  ugp "$_TERM_ID" # `type ugp`
usrlog.sh: https://github.com/westurner/dotfiles/blob/master/scripts/us...
Interesting way of aliasing right from where you use it! I actually replaced my default shell history search with fuzzy search using (https://github.com/junegunn/fzf), I can highly recommend it!
Huh, apparently I've already starred that. It must have been posted on HN at some point.
Interesting, I think there’s a shopt that I’m missing. When I append a comment, it’s not recorded in bash history, as I’d expect.