• The strange syntax for shell shortcut binding with bind command.

    From hongyi.zhao@gmail.com@21:1/5 to All on Sun Aug 29 19:09:06 2021
    I use hstr [1] to view, navigate, search and manage my command history, which uses the following keyboard shortcut binding:

    $ bind -S
    \C-r outputs \C-a hstr -- \C-j
    \C-xk outputs \C-a hstr -k \C-j

    I've checked the built-in help of bind command, but still don’t understand how these keyboard shortcuts work.

    Any more hints will be highly appreciated.

    [1] https://github.com/dvorka/hstr

    Regards,
    HY

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to hongy...@gmail.com on Mon Aug 30 04:33:23 2021
    You should mention that you are asking for a _bash_ specific 'bind'
    function. - Doesn't the bash man page explains it?

    On 30.08.2021 04:09, hongy...@gmail.com wrote:
    I use hstr [1] to view, navigate, search and manage my command history, which uses the following keyboard shortcut binding:

    $ bind -S
    \C-r outputs \C-a hstr -- \C-j
    \C-xk outputs \C-a hstr -k \C-j

    I've checked the built-in help of bind command, but still don’t understand how these keyboard shortcuts work.

    Any more hints will be highly appreciated.

    [1] https://github.com/dvorka/hstr

    Regards,
    HY


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From hongyi.zhao@gmail.com@21:1/5 to Janis Papanagnou on Sun Aug 29 19:47:38 2021
    On Monday, August 30, 2021 at 10:33:27 AM UTC+8, Janis Papanagnou wrote:
    You should mention that you are asking for a _bash_ specific 'bind' function. - Doesn't the bash man page explains it?

    Yes. There are some explanations in bash man page:

    ###################
    $ help bind
    bind: bind [-lpsvPSVX] [-m keymap] [-f filename] [-q name] [-u name] [-r keyseq] [-x keyseq:shell-command] [keyseq:readline-function or readline-command]
    Set Readline key bindings and variables.

    Bind a key sequence to a Readline function or a macro, or set a
    Readline variable. The non-option argument syntax is equivalent to
    that found in ~/.inputrc, but must be passed as a single argument:
    e.g., bind '"\C-x\C-r": re-read-init-file'.

    Options:
    -m keymap Use KEYMAP as the keymap for the duration of this
    command. Acceptable keymap names are emacs,
    emacs-standard, emacs-meta, emacs-ctlx, vi, vi-move,
    vi-command, and vi-insert.
    -l List names of functions.
    -P List function names and bindings.
    -p List functions and bindings in a form that can be
    reused as input.
    -S List key sequences that invoke macros and their values
    -s List key sequences that invoke macros and their values
    in a form that can be reused as input.
    -V List variable names and values
    -v List variable names and values in a form that can
    be reused as input.
    -q function-name Query about which keys invoke the named function.
    -u function-name Unbind all keys which are bound to the named function.
    -r keyseq Remove the binding for KEYSEQ.
    -f filename Read key bindings from FILENAME.
    -x keyseq:shell-command Cause SHELL-COMMAND to be executed when
    KEYSEQ is entered.
    -X List key sequences bound with -x and associated commands
    in a form that can be reused as input.

    Exit Status:
    bind returns 0 unless an unrecognized option is given or an error occurs. ###################

    But I've previously checked the following:

    $ man bind

    BIND(2) Linux Programmer's Manual BIND(2)

    NAME
    bind - bind a name to a socket

    Regards,
    HY

    On 30.08.2021 04:09, hongy...@gmail.com wrote:
    I use hstr [1] to view, navigate, search and manage my command history, which uses the following keyboard shortcut binding:

    $ bind -S
    \C-r outputs \C-a hstr -- \C-j
    \C-xk outputs \C-a hstr -k \C-j

    I've checked the built-in help of bind command, but still don’t understand how these keyboard shortcuts work.

    Any more hints will be highly appreciated.

    [1] https://github.com/dvorka/hstr

    Regards,
    HY


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to hongy...@gmail.com on Mon Aug 30 05:32:06 2021
    On 30.08.2021 04:47, hongy...@gmail.com wrote:
    On Monday, August 30, 2021 at 10:33:27 AM UTC+8, Janis Papanagnou wrote:
    You should mention that you are asking for a _bash_ specific 'bind'
    function. - Doesn't the bash man page explains it?

    Yes. There are some explanations in bash man page:

    ###################
    $ help bind
    bind: bind [-lpsvPSVX] [-m keymap] [-f filename] [-q name] [-u name] [-r keyseq] [-x keyseq:shell-command] [keyseq:readline-function or readline-command]
    Set Readline key bindings and variables.
    [...]
    ###################

    But I've previously checked the following:

    $ man bind

    BIND(2) Linux Programmer's Manual BIND(2)

    NAME
    bind - bind a name to a socket

    This is obviously something completely different. Type

    man man

    to see what you find in the various man page sections. Don't expect
    that you find 'bash' functions in the Unix system calls section (2)!

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From hongyi.zhao@gmail.com@21:1/5 to Janis Papanagnou on Sun Aug 29 21:58:10 2021
    On Monday, August 30, 2021 at 11:32:10 AM UTC+8, Janis Papanagnou wrote:
    On 30.08.2021 04:47, hongy...@gmail.com wrote:
    On Monday, August 30, 2021 at 10:33:27 AM UTC+8, Janis Papanagnou wrote:
    You should mention that you are asking for a _bash_ specific 'bind'
    function. - Doesn't the bash man page explains it?

    Yes. There are some explanations in bash man page:

    ###################
    $ help bind
    bind: bind [-lpsvPSVX] [-m keymap] [-f filename] [-q name] [-u name] [-r keyseq] [-x keyseq:shell-command] [keyseq:readline-function or readline-command]
    Set Readline key bindings and variables.
    [...]
    ###################

    But I've previously checked the following:

    $ man bind

    BIND(2) Linux Programmer's Manual BIND(2)

    NAME
    bind - bind a name to a socket
    This is obviously something completely different. Type

    man man

    to see what you find in the various man page sections. Don't expect
    that you find 'bash' functions in the Unix system calls section (2)!

    What do you mean by saying ``(2)! '' here?

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to hongy...@gmail.com on Mon Aug 30 11:51:25 2021
    On 30.08.2021 06:58, hongy...@gmail.com wrote:
    On Monday, August 30, 2021 at 11:32:10 AM UTC+8, Janis Papanagnou wrote:
    On 30.08.2021 04:47, hongy...@gmail.com wrote:
    On Monday, August 30, 2021 at 10:33:27 AM UTC+8, Janis Papanagnou wrote: >>>> You should mention that you are asking for a _bash_ specific 'bind'
    function. - Doesn't the bash man page explains it?

    Yes. There are some explanations in bash man page:

    ###################
    $ help bind
    bind: bind [-lpsvPSVX] [-m keymap] [-f filename] [-q name] [-u name] [-r keyseq] [-x keyseq:shell-command] [keyseq:readline-function or readline-command]
    Set Readline key bindings and variables.
    [...]
    ###################

    But I've previously checked the following:

    $ man bind

    BIND(2) Linux Programmer's Manual BIND(2)

    NAME
    bind - bind a name to a socket
    This is obviously something completely different. Type

    man man

    to see what you find in the various man page sections. Don't expect
    that you find 'bash' functions in the Unix system calls section (2)!

    What do you mean by saying ``(2)! '' here?

    The exclamation mark is a regular grammatical punctuation character to terminate the sentence. The number (2) is a manual page section number.
    The man pages are separated in sections. You see that number e.g. above
    in: "BIND(2) Linux Programmer's Manual BIND(2)"

    You find (as already said) a list when calling the man page of 'man'
    man man

    ...
    The table below shows the section numbers of the manual followed by the
    types of pages they contain.

    1 Executable programs or shell commands
    2 System calls (functions provided by the kernel)
    3 Library calls (functions within program libraries)
    4 Special files (usually found in /dev)
    5 File formats and conventions eg /etc/passwd
    6 Games
    7 Miscellaneous (including macro packages and
    conventions), e.g.
    man(7), groff(7)
    8 System administration commands (usually only for root)
    9 Kernel routines [Non standard]
    ...

    Section 1 has what you typically call as commands from the shell.
    Section 2 has what you typically call as system function in C programs.

    The man command will show the first matching section. If you want to
    get the command from another section call it with an explicit number.
    Compare the output of
    man link
    man 1 link
    man 2 link

    Try, for example,
    man passwd
    and inspect the "see also" references on the bottom of the page where
    you see the section numbers of the respective ressources

    SEE ALSO
    passwd(5), shadow(5), usermod(8).

    then type
    man 5 passwd
    to find information about the file formats.

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Josef Moellers@21:1/5 to All on Mon Aug 30 14:51:27 2021
    On 30.08.21 11:51, Janis Papanagnou wrote:

    Just to be nitpicking, as I have been bitten by this (really badly!):

    You find (as already said) a list when calling the man page of 'man'
    man man

    ...
    The table below shows the section numbers of the manual followed by the
    types of pages they contain.

    1 Executable programs or shell commands
    2 System calls (functions provided by the kernel)

    These *used to be* "functions provided by the kernel". While there still
    is a *system call" "sys_open", the "open(2)" function is now often
    implemented through the system call "sys_openat":
    "Since version 2.26, the glibc wrapper function for open() employs the
    openat() system call, rather than the kernel's open() system call. For certain architectures, this is also true in glibc versions before 2.26."
    [man 2 open]

    This may be important when you eg want to block open(2) system calls
    through systemd or you want to explicitly trace open(2) calls with
    strace and you wonder why this does not work.

    In a nutshell: do not rely on the fact that the function is described in
    manual section 2!

    Josef

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)