2013-11-03 14 views
9

Tôi đã tìm kiếm man bash, nhưng không thể tìm thấy bất kỳ thứ gì liệt kê tất cả các ràng buộc khóa bind -x hiện tại. Có cách nào tôi có thể làm điều đó không? Tôi đã thử các cách sau:Danh sách bash "bind -x" bindings

$ bind -x '"\C-`":"echo hello"' 
# test binding: press CTRL+` 
hello 
# Binding works! 
$ bind -p | grep 'hello' 
# no output 
$ bind -S 
# no output 

Vì vậy, có cách nào tôi có thể xem danh sách tất cả bind -x hiện đang hoạt động không?

Trả lời

3

Có vẻ như bạn có thể sử dụng bind -X (mới trong Bash 4,3):

$ help bind 
     ... 
     -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. 
     ... 
$ 
+1

Tôi không biết bạn đang sử dụng phiên bản bash nào, nhưng đối với tôi 'bind -X' trả về' invalid option'. Thật vậy, 'help bind' không liệt kê' -X' cho tôi. Trên máy của tôi, 'bash --version' tạo' phiên bản 4.2.45 (1) -release (x86_64-pc-linux-gnu) ' – Samee

+1

Tôi đang sử dụng 4.3 (beta). Tôi không biết đó là một tính năng mới được thêm vào. :) – pynexj

+0

Huh! Vì vậy, tôi đoán tôi sẽ chỉ treo chặt sau đó :-P Bạn có biết lịch phát hành/giải pháp thay thế cho 4.2 không? – Samee

1

Câu trả lời ở trên trở ra trống trên bash 4.3.48 cho tôi. Nhưng vốn 'P' làm việc:

ràng buộc - hiển thị tất cả các tên hàm (và bindings)

bind -P 

Giải thích

  -P  List current readline function names and bindings. 
      -p  Display readline function names and bindings in such a 
       way that they can be re-read. 

Mẫu đầu ra

set-mark can be found on "\[email protected]", "\e ". 
shell-expand-line can be found on "\e\C-e". 
start-kbd-macro can be found on "\C-x(". 
tilde-expand can be found on "\e&". 
transpose-chars can be found on "\C-t". 
transpose-words can be found on "\et". 
undo can be found on "\C-x\C-u", "\C-_". 
unix-line-discard can be found on "\C-u". 
unix-word-rubout can be found on "\C-w". 
upcase-word can be found on "\eu". 
yank can be found on "\C-y". 
yank-last-arg can be found on "\e.", "\e_". 
yank-nth-arg can be found on "\e\C-y". 
yank-pop can be found on "\ey". 

manpage

Vì việc tìm manpage cho trang này rất khó khăn, ở đây là:

bind [-m keymap] [-lpsvPSVX] 
     bind [-m keymap] [-q function] [-u function] [-r keyseq] 
     bind [-m keymap] -f filename 
     bind [-m keymap] -x keyseq:shell-command 
     bind [-m keymap] keyseq:function-name 
     bind readline-command 
       Display current readline key and function bindings, bind a key 
       sequence to a readline function or macro, or set a readline 
       variable. Each non-option argument is a command as it would 
       appear in .inputrc, but each binding or command must be passed 
       as a separate argument; e.g., '"\C-x\C-r": re-read-init-file'. 
       Options, if supplied, have the following meanings: 
       -m keymap 
        Use keymap as the keymap to be affected by the subsequent 
        bindings. Acceptable keymap names are emacs, 
        emacs-standard, emacs-meta, emacs-ctlx, vi, vi-move, 
        vi-command, and vi-insert. vi is equivalent to 
        vi-command; emacs is equivalent to emacs-standard. 
       -l  List the names of all readline functions. 
       -p  Display readline function names and bindings in such a 
        way that they can be re-read. 
       -P  List current readline function names and bindings. 
       -s  Display readline key sequences bound to macros and the 
        strings they output in such a way that they can be re- 
        read. 
       -S  Display readline key sequences bound to macros and the 
        strings they output. 
       -v  Display readline variable names and values in such a way 
        that they can be re-read. 
       -V  List current readline variable names and values. 
       -f filename 
        Read key bindings from filename. 
       -q function 
        Query about which keys invoke the named function. 
       -u function 
        Unbind all keys bound to the named function. 
       -r keyseq 
        Remove any current binding for keyseq. 
       -x keyseq:shell-command 
        Cause shell-command to be executed whenever keyseq is 
        entered. When shell-command is executed, the shell sets 
        the READLINE_LINE variable to the contents of the 
        readline line buffer and the READLINE_POINT variable to 
        the current location of the insertion point. If the 
        executed command changes the value of READLINE_LINE or 
        READLINE_POINT, those new values will be reflected in the 
        editing state. 
       -X  List all key sequences bound to shell commands and the 
        associated commands in a format that can be reused as 
        input. 

       The return value is 0 unless an unrecognized option is given or 
       an error occurred. 
+0

Tôi nên sử dụng lệnh nào để xem trang hướng dẫn sử dụng? Bất cứ khi nào tôi chạy 'man bind' nó cho tôi thấy manpage để gắn một tên vào một ổ cắm – kshenoy

+0

Tôi chỉ có thể tiếp cận thông tin này thông qua trang người dùng dựa trên web của chúng tôi. Từ dòng lệnh tôi mơ hồ, u nhớ lại thông tin này rất khó tìm. –

+0

https://www.gnu.org/software/bash/manual/html_node/Bash-Builtins.html#Bash-Builtins – tripleee

Các vấn đề liên quan