# ~/.inputrc - local inputrc for libreadline
# vim: ft=config:fdm=marker:fdl=0:noml:
# see readline(3readline) and `info rluserman' for more information.
# https://wiki.archlinux.org/index.php/readline
# note: use ^x^r to re-read this file after modification
#$include /etc/inputrc

set bell-style none
set completion-ignore-case On
# underscores=hyphens
set completion-map-case On
set completion-query-items -1
#set completion-query-items 500
# don't display control characters like ^C if I input them
set echo-control-characters Off
# disable highlighted paste feature Bash >= 5.1
#set enable-bracketed-paste Off
# keep cursor column when iterating through history
set history-preserve-point On
##set horizontal-scroll-mode On
# reduce delay to recognise escape (in ms) DEFAULT: 500
##set keyseq-timeout 400
# add a trailing "/" for symlinked directories
#set mark-directories On
set mark-symlinked-directories On
# don't paginate completions (default: on)
set page-completions Off
# goes nicely with ls(1) -x/--format=across
#set print-completions-horizontally On
# don't actually modify my history
set revert-all-at-newline On
# one <tab> to get show all possible completions
set show-all-if-ambiguous On
# set show-all-if-unmodified On
# don't re-complete already completed text in the middle of a word. Bash >= 4
# "cd ~/src/repo" -> cursor on p => <tab> "cd ~/src/mozilla"
set skip-completed-text On
# append characters to indicate completion filetype, like ls(1) -F
set visible-stats On

# UTF-8 support
# UTF-8 input and output, instead of showing stuff like $'\0123\0456'
# don't strip characters to 7 bits when reading
set input-meta On
# allow iso-latin1 characters - not converted to prefix-meta sequences
set convert-meta Off
# display eighth bit characters directly - not as meta-prefixed characters
set output-meta On

# keys
## <c-left> <c-right> | mappings for word moving
"\e[1;5C": forward-word
"\e[1;5D": backward-word
"\e[5C": forward-word
"\e[5D": backward-word
"\e\e[C": forward-word
"\e\e[D": backward-word
# <alt-del> | delete preceding word
"\e[3;3~": backward-kill-word
# <c-del> | delete word after
"\e[3;5~": kill-word

# vi
# note: this must be done before the settings below
set editing-mode vi
set keymap vi
set show-mode-in-prompt on
set vi-ins-mode-string ""
set vi-cmd-mode-string ":"
# set vi-cmd-mode-string "\1\e[2 q\2"
# set vi-ins-mode-string "\1\e[6 q\2"
# $if term=linux
# set vi-ins-mode-string \1\e[?0c\2
# set vi-cmd-mode-string \1\e[?8c\2
# $if term=foot
# set show-mode-in-prompt on
# set emacs-mode-string "\1\e]133;A\e\\\2"
# # uncomment and/or adjust if using vi editing-mode.
# set vi-cmd-mode-string "\1\e]133;A\e\\\2"
# set vi-ins-mode-string "\1\e]133;A\e\\\2"
# $endif
# $else
# set vi-ins-mode-string \1\e[6 q\2
# set vi-cmd-mode-string \1\e[2 q\2
# $endif

# bindings
## <tab> | cycles forward through completion choices.
"\t": menu-complete
## <shift-tab> | cycles backward through completion choices.
"\e[Z": menu-complete-backward

$if Bash
Space: magic-space
## <tab> cycles forward through completion choices.
TAB: menu-complete
# M-TAB: dynamic-complete-history
"\e\C-i": dynamic-complete-history
## <shift-tab> cycles backward through completion choices.
"\e[Z": menu-complete-backward
## <up/down> | substring history search
"\e[A": history-search-backward
"\e[B": history-search-forward
## c-{left,right} | jump over words do history expansion when space entered
## defult c-{left,right} jump over words, instead jump as shell tokenizes line
"\e[1;3C": shell-forward-word
"\e[1;3D": shell-backward-word
"\e[3C": shell-forward-word
"\e[3D": shell-backward-word
"\C-a": beginning-of-line
"\C-b": backward-char
"\C-e": end-of-line
"\C-f": forward-char

set keymap vi-command
":": execute-named-command
"gg": beginning-of-history
"G": end-of-history
"H": beginning-of-line
"L": end-of-line
"\C-a": vi-insert-beg
"\C-e": vi-append-eol
"\C-u": backward-kill-line
"\C-v": vi-edit-and-execute-command
"\C-w": unix-word-rubout

set keymap vi-insert
"\t": menu-complete
"\e[Z": menu-complete-backward
"\e[A": history-search-backward
"\e[B": history-search-forward
"jk": vi-movement-mode
"\C-a": beginning-of-line
"\C-b": backward-char
#"\C-d": unix-filename-rubout
#"\C-d": kill-whole-line
"\C-e": end-of-line
"\C-f": forward-char
"\C-k": kill-line
"\C-l": clear-screen
"\C-n": next-history
"\C-p": previous-history
#"\C-u": backward-kill-line
#"\C-w": backward-kill-word
#"\C-@": history-and-alias-expand-line
"\C-]": dabbrev-expand
"\C-x*": glob-expand-word
"\C-xa": alias-expand-line
"\C-xd": dump-macros
"\C-xq": quoted-insert
"\C-x\C-e": edit-and-execute-command
"\C-x\C-k": kill-whole-line
"\C-x\C-u": undo
"\C-x\C-x": exchange-point-and-mark
## cycle through the last argument of previous commands with alt + .
#"\e.": yank-last-arg
"\e.": insert-last-argument
#"\e:": execute-named-command
"\e{": complete-into-braces
"\ee": shell-expand-line
# move forward by whitespace-delimited word
# "\ef":vi-fWord
# "\eb":vi-bWord
# "\eB": vi-bword
# "\eF": vi-fword
"\eb": vi-backward-word
"\eB": vi-backward-bigword
"\ed": kill-word
"\eD": shell-kill-word
"\ef": vi-forward-word
"\eF": vi-forward-bigword
"\en": history-substring-search-forward
"\ep": history-substring-search-backward
"\et": transpose-words
"\eT": shell-transpose-words
"\eu": vi-undo
"\e\C-]": character-search-backward
"\e\C-e": shell-expand-line
"\e\C-i": dynamic-complete-history
"\e\C-r": revert-line
"\e\C-y": yank-nth-arg

"\C-g": "fg\C-m"
#"\C-x_": "/dev/null"
"\C-x?": "; echo $?"
"\C-x\`": "\$()\C-b"
# automatic inputting '' or "" and move the cursor
"\C-x\'": "'' \e[D\e[D"
"\C-x\"": "\"\" \e[D\e[D"
"\C-xb": "\${}\C-b"
## run-again
"\C-xk": "\e[A\C-m"
"\C-xl": "\C-e | less\C-m"
"\C-xp": "\eB\printf '%s\\n' \ef"
# wrap a command in $( ... )
# "\C-xq": "\C-a\$(\C-e)"
# timestamping
# "\C-xt": "\"$(date -u +%Y-%m-%dT%H:%M:%SZ)\" "
# "\ev": "\e$a | $EDITOR\C-m"
"\C-xw": "\e$a | awk '{ print $ }'\C-b\C-b\C-b"
"\C-x\C-w": "while read -r f\e$a; do ; done\eb\C-b\C-b"

#"\C-x\C-z": "%-\C-m"
"\e=": "; echo $?"
## /dev/null
#"\e;": ">/dev/null 2>&1\C-m"
## log
#"\e;": "2>&1 |tee log\C-m"
## ps
#"\ep": "\C-ups -U $USER\C-m"

# <a-'> | for escaped single-quote
# "\e'": "'\\''"
# "\e\"": "\e[1;3D\"\C-e\""
"\ea": "\C-a\e[3;5~"
"\el":"\C-uls -tr\C-m"
"\er": "\C-asudo \C-e"
## <a-s> | (for set) - wrap current command in (set -x ; ..)
"\es": "\C-a(set -x ; \C-e)\C-b"
## <a-v> | move to end of line with $ and pipe commands output to editor
"\ev": "\e$a | $EDITOR\C-m"
"\ew": "\C-atype \C-e\C-m"
## xargs
"\ex": "\C-ufind . -print0 -name \"**\" 2>/dev/null| xargs -0\C-a\ef\ef\ef\C-f\C-f\C-f"
#"\eD": "\eF\C-w"
"\eH": " --help"
"\eL": "\C-e\| (jq -C . | less -RSX)"
"\eV": " --version"
"\eX": "\$\(!-1 \| tail -n 1\)\e\C-e"
# <alt-c-b> | send command into background silently
#"\e\C-b": "\C-e >/dev/null 2>&1 &\C-m"
# <alt-c-b> | move backward a shell-quoted word
#"\e\C-b": shell-backward-word
# <alt-c-f> | move forward a shell-quoted word
#"\e\C-f": shell-forward-word
# <alt-c-w> | delete a previous shell-quoted word
# "\e\C-w": shell-backward-kill-word
# <f1> | append man
"\eOP": "\C-a\man \C-e\C-m"

# fzf | wrap the current command in $( .... | fzf)
"\C-xf": "\C-e | fzf --exit-0 --multi --ansi --height=40)\C-a \$(\C-a"

# $if term=xterm-kitty
# "\C-l": clear-display
# $endif
# $if term=xterm-256color
# "\C-l": clear-display
# $endif
# <c-w> within a line | workaround Bash ≥ 4.4 bug
# see: https://bugs.debian.org/838437
#"\C-w": unix-word-rubout
set bind-tty-special-chars Off
"\C-w": backward-kill-word

# default to re-read .inputrc
"\C-x\C-r": re-read-init-file
$endif

#"\C-o": rlwrap-call-editor

# bc | don't let bc complete filenames (!?)
$if bc
Tab:
$endif

# ed
$if ed
Control-n: menu-complete
$endif

# python | regain ability to paste multiple commands
$if Python
set enable-bracketed-paste off
"^I": rl_complete
$endif
