I want to control and use command line history better

Forum Forums General Tips and Tricks I want to control and use command line history better

  • This topic has 36 replies, 6 voices, and was last updated Mar 15-8:35 pm by Brian Masinick.
Viewing 7 posts - 31 through 37 (of 37 total)
  • Author
    Posts
  • #55084
    Moderator
    Brian Masinick
      Helpful
      Up
      0
      ::

      Is the

      super + r

      aka the windows key being used for other anything?

      I’m not sure but you are right in your thoughts.

      As far as I know only a couple of Ctrl and Esc mappings are used so this key binding is worth trying.

      --
      Brian Masinick

      #55090
      Moderator
      Brian Masinick
        Helpful
        Up
        0
        ::

        Notice that this thread is now in the Tips and Tricks section as recommended.

        I looked at the other tool with the fuzzy searching that can be used with Vim-style methods. For those who want to search for their shell history for a particular pattern this might be handy, but even like hstr, both searching and selecting particular items can actually be managed with the standard history because both Emacs and Vi-style Bash search capabilities are plenty powerful in their own right. Not only that, if you set your history size large enough, you can find commands that you typed that go as far back as your history simply by typing in the history command from a shell prompt. You can, if you want, write that to a file if it is helpful, (though it really isn’t necessary).

        I’d say for the sake of BobC, hstr is the right command for additional convenience, and mapping the bash hstr command to something like F5 or Super + R is an appropriate solution to achieve what BobC is searching for.

        Now the only remaining thing to discuss is whether you know how to create a key mapping and put it in your Bash resource file (which is .bashrc). IF this is known and clear, we are done; otherwise feel free to either ASK or POST your recommended Bash (.bashrc) key binding for the command hstr.

        --
        Brian Masinick

        #55092
        Moderator
        Brian Masinick
          Helpful
          Up
          0
          ::

          Here are a few resources for creating your own Bash key bindings:

          https://www.computerhope.com/unix/bash/bind.htm
          https://stackoverflow.com/questions/4200800/in-bash-how-do-i-bind-a-function-key-to-a-command
          https://unix.stackexchange.com/questions/89622/how-to-execute-a-script-in-shell-when-a-shortcut-key-is-pressed
          https://www.youtube.com/watch?v=EzIqCeGHRpM

          bind -p
          will show the bindings of every key sequence, including the ones that have already been assigned, so that is helpful for determining which key sequences may be available for your personal use.

          I hope that these answer any remaining questions; if not, please ask a specific question and explain the scenario you are interested in.

          • This reply was modified 2 years, 2 months ago by Brian Masinick.

          --
          Brian Masinick

          #55648
          Moderator
          BobC
            Helpful
            Up
            0
            ::

            I am thinking that this hotkey belongs in the bash setup, and my solution is to add an alias hs to run hstr.

            #55794
            Moderator
            BobC
              Helpful
              Up
              0
              ::

              I finally figured out how to program Alt-r, not sure which is better…

              bind '"ò":"hstr\n"'

              Odd, it worked to echo foobar, but after that never worked again. My give up. I guess I’ll type hs and press enter. It’s not perfect, but it might be me or how I’m trying to use it…

              • This reply was modified 2 years, 1 month ago by BobC.
              #55826
              Anonymous
                Helpful
                Up
                0
                ::

                re: the topic title “I want to control and use command line history better”, here a a couple tips:

                We can add breadcrumb notes-to-self into the history list.
                Prepend a “:” colon at beginning of line then type whatever and press enter.
                The shell interpreter will treat the line as a “no-op”, yet the will be inserted into history.

                We can avoid commandstrings containing sensitive (passwords, etc) info being stored to history
                by prepending one or more spaces at beginning-of-line.

                ^— these work for me, using bash.
                I haven’t checked whether they are universally effective across various shells.

                #55841
                Moderator
                Brian Masinick
                  Helpful
                  Up
                  0
                  ::

                  I got a bit different result:
                  On one hand, a line with : at the beginning WILL be in the command history, but if I write:
                  : This is a comment
                  (does appear in history but issues a command syntax error)

                  I get a syntax error, though it DOES show up in the command history.
                  However, if I write:
                  # This is a comment,
                  it *literally* IS interpreted as a comment.
                  (and appears in command history)

                  However, if I put a space or two in front of a colon (:) them it is ALSO interpreted as a comment, and shows up in history.

                  For example,
                  : two spaces, then colon is interpreted as a comment
                  If you add parentheses, these want to be interpreted, so it doesn’t work with :
                  You CAN use parentheses IF you use # as the comment indicator at the beginning of the line.
                  !# is NOT a comment; this tells the shell – at least as the first line, to interpret the next argument

                  I found THIS in the BASH man page regarding the use of comments:

                  COMMENTS
                  In a non-interactive shell, or an interactive shell in which the
                  interactive_comments option to the shopt builtin is enabled (see
                  SHELL BUILTIN COMMANDS below), a word beginning with # causes
                  that word and all remaining characters on that line to be
                  ignored. An interactive shell without the interactive_comments
                  option enabled does not allow comments. The interactive_comments
                  option is on by default in interactive shells.

                  SHELLOPTS
                  A colon-separated list of enabled shell options. Each
                  word in the list is a valid argument for the -o option to
                  the set builtin command (see SHELL BUILTIN COMMANDS
                  below). The options appearing in SHELLOPTS are those
                  reported as on by set -o. If this variable is in the
                  environment when bash starts up, each shell option in the
                  list will be enabled before reading any startup files.
                  This variable is read-only.

                  [-+]O [shopt_option]
                  shopt_option is one of the shell options accepted by the
                  shopt builtin (see SHELL BUILTIN COMMANDS below). If
                  shopt_option is present, -O sets the value of that option; +O
                  unsets it. If shopt_option is not supplied, the names and
                  values of the shell options accepted by shopt are printed on
                  of the extdebug option to the shopt builtin below).

                  shopt [-pqsu] [-o] [optname …]
                  If either -s or -u is used with no optname arguments, shopt
                  Unless otherwise noted, the shopt options are disabled (unset)

                  • This reply was modified 2 years, 1 month ago by Brian Masinick.

                  --
                  Brian Masinick

                Viewing 7 posts - 31 through 37 (of 37 total)
                • You must be logged in to reply to this topic.