interpreters.org (3680B)
1 * Shell 2 ** Add faces instead of reusing font-lock-{comment,string} 3 ** Improve directory tracking 4 Ensure ~default-directory~ remains consistent with the shell's current 5 working directory. Some things ~shell-mode~ does not handle: 6 7 - ~autocd~ (there's ~shell-has-auto-cd~, but it does not track whether 8 ~autocd~ is *actually* set) 9 - ~cd !$~ 10 - ~ssh~ 11 - Docker containers 12 13 Some solutions: 14 - Emacs 28's ~comint-osc-process-output~ 15 - requires configuring the prompt 16 - does not handle SSH (yet) 17 - relies on OSC 7, which is [[https://gitlab.freedesktop.org/terminal-wg/specifications/-/issues/20][not standard yet]] 18 - running this clumsy thing after every command: 19 #+begin_src sh 20 (file-truename 21 (format "/proc/%d/cwd" 22 (process-id (get-buffer-process (current-buffer))))) 23 #+end_src 24 25 ** Use Bash completions 26 Emacs filename completions in =*shell*= are subtly different to 27 Bash's; e.g. typing ~ls TAB~ in a folder with a single file expands to 28 ~ls that-file~. 29 30 Also, in general, =*shell*= has no clue about 31 32 - changes to =$PATH=, which affect what programs are available, 33 - changes to the current working directory not triggered by an 34 explicit ~cd~, and not announced by OSC 7, 35 - commands (functions, aliases) defined… 36 - in startup files (=.bashrc= et al.), 37 - during the interactive session, 38 - programmable completions contributed by authors of CLI applications. 39 40 Querying Bash for completions would solve all of the above. 41 42 See [[https://debbugs.gnu.org/26661][bug#26661]], and [[https://github.com/szermatt/emacs-bash-completion/issues/45][szermatt/emacs-bash-completion!45]]. 43 ** Handle DECSC, DECRC, CUU, ED, HVP and DECSTBM console codes 44 Used for APT's "Dpkg::Progress-Fancy" option, enabled by default with 45 the high-level apt(8) command. Silly script emulating what APT does: 46 #+begin_src bash 47 #!/bin/bash 48 49 set -eu 50 51 if ! test "${LINES:-}" -a "${COLUMNS:-}" 52 then 53 echo Please export LINES and COLUMNS. 54 exit 1 55 fi 56 57 # Adapted from apt/apt-pkg/install-progress.cc. 58 59 backup=$'\e7' # DECSC: backup cursor position. 60 restore=$'\e8' # DECRC: restore cursor position. 61 62 setup () 63 { 64 echo -n ${backup} 65 # DECSTBM: restrict scrolling below command, and above progress 66 # bar. Side-effect: move the cursor to position 1:1, 67 # hence the backup/restore. 68 echo -n $'\e[0;'$((LINES-1))'r' 69 echo -n ${restore} 70 } 71 72 teardown () 73 { 74 # ED: clear everything from current position to end of screen. 75 # Dixit Michael Vogt: "sledgehammer". 76 echo -n $'\e[J' 77 } 78 79 # APT surrounds this setup phase with \n and \e[1A (CUU). I don't 80 # know why; the comments say that this is to "avoid visual glitch when 81 # the screen area shrinks by one row". No further explanation is 82 # given in commit messages. 83 setup 84 85 for ((i=1;i<COLUMNS-1;i++)) 86 do 87 if ! ((i%10)) 88 then 89 echo "installing stuff" 90 fi 91 92 echo -n ${backup} 93 94 # HVP: move cursor to last line, first column. 95 echo -n $'\e['${LINES}';1f' 96 97 # Draw progress bar. 98 progress='[' 99 for ((j=1;j<=i;j++)) 100 do 101 progress+='#' 102 done 103 for ((j=i+1;j<COLUMNS-1;j++)) 104 do 105 progress+='.' 106 done 107 progress+=']' 108 echo -n ${progress} 109 110 echo -n ${restore} 111 112 sleep 0.1 113 done 114 115 teardown 116 #+end_src 117 118 * Eshell 119 ** ~ls --group-directories-first~ does not color folders 120 * Python shell 121 ** Handle ~completion-prefix-display-length~ 122 Setting this variable in an inputrc file causes the Python interpreter 123 to elide common prefixes when showing completion candidates. This 124 seems to confuse python-shell-completion-native-get-completions (at 125 best hitting TAB yields "No match", at worst it makes Emacs hang).