This is the second day of my participation in Gwen Challenge

This article is based on Arthas version 3.5.1 and introduces the use and implementation of basic commands PWD, Plaintext, WC,keymap.

A. The PWD command

Returns the current working directory, similar to the Linux command

Files at com.taobao.arthas.core.com mand. Basic1000. PwdCommand. Java.

New File(“”).getabsolutePath () returns the current working directory.

Second, plaintext command

Remove ANSI colors from the output

Files at com.taobao.arthas.core.shell.com mand. Internal. PlainTextHandler. Java.

Actually is the method called RenderUtil ansiToPlainText.

The method removes the color and then outputs the text by passing the\u001b[[;\d]*mReplace to achieve ANSI color removal.

3. The wc command

Statistics the output by row.

Files at com.taobao.arthas.core.shell.com mand. Internal. WordCountHandler. Java.

The parameter name Parameters of the abbreviations Parameters that mandatory The sample
-l Count the number of output lines mandatory jad demo.MathGame main | wc -l

Split statistics by rowinput.split("\n").length.

4. Keymap command

The keymap command displays the current shortcut key mapping list. The keymap command can be used only in terminal mode.

The default output is as follows:

shortcuts Shortcut Keys Name of the command The command that
\C-a ctrl + a beginning-of-line Jump to the beginning of a line
\C-e ctrl + e end-of-line Jump to the end of each line
\C-f ctrl + f forward-word Move one word forward
\C-b ctrl + b backward-word Move one word back
\e[D Keyboard left arrow key backward-char Move the cursor forward one character
\e[C Keyboard right arrow key forward-char Move the cursor back one character
\e[A Arrow keys on the keyboard history-search-backward Scroll up to display the previous command
\e[B Arrow keys under the keyboard history-search-forward Scroll down to show the next command
\C-h ctrl + h backward-delete-char Deletes one character backwards
\C-? ctrl + shift + / backward-delete-char Deletes one character backwards
\C-u ctrl + u undo To undo the previous command is equivalent to clearing the current line
\C-d ctrl + d delete-char Deletes the character where the cursor is located
\C-k ctrl + k kill-line Deletes all characters from the current cursor to the end of the line
\C-i ctrl + i complete Automatic completion, equivalent to pressing TAB
\C-j ctrl + j accept-line Ending the current line is equivalent to hitting enter
\C-m ctrl + m accept-line Ending the current line is equivalent to hitting enter

Files at com.taobao.arthas.core.com mand. Basic1000. KeymapCommand. Java.

The helper.loadInputrcfile () method obtains the shortcut key

1. The load directory $USER_HOME /. Arthas/conf/inputrc shortcuts for user-defined file 2. . Get the default file ShellServerOptions DEFAULT_INPUTRC namely path for com/taobao/arthas/core/shell/term/readline inputrc file. 3. If not found the use of com. Alibaba. Middleware: termd – corejar package the shortcut file, otherwise an error cannot load this file. \

After reading, if the description starting with # is a comment, ignore it and use colons to separate the shortcut keys and command names. The renderUtil. render method generates string content in tabular form.