Просмотр исходного кода

Add `cu` alias and completion

`cu` can be used in any terminal emulator to talk to serial
devices/consoles/ports, instead of using a dedicated console application
like ZTerm. This is useful for managing cisco devices, for example.

Also got to learn about the zsh completion system. Now, any custom
completions that we do not want to turn into a plugin can be put in
`zsh/custom/completions`.
Weiyi Lou 10 лет назад
Родитель
Сommit
2621fe3f0b
3 измененных файлов с 39 добавлено и 0 удалено
  1. 4 0
      zsh/custom/aliases-misc.zsh
  2. 32 0
      zsh/custom/completions/_cu
  3. 3 0
      zsh/zshrc

+ 4 - 0
zsh/custom/aliases-misc.zsh

@@ -4,6 +4,10 @@ alias hosts='sudo vim /etc/hosts'
 # Common places
 alias cd.='cd ~/dotfiles'
 
+# Serial console access ("call up line"). Type `~.` (and wait) to disconnect.
+alias cul='sudo cu -s 9600 -l'
+compdef _cu cul
+
 # Folder listing/traversal, least to most detailed
 alias l='ls'
 alias la='ls -A'

+ 32 - 0
zsh/custom/completions/_cu

@@ -0,0 +1,32 @@
+#compdef cu
+
+# Completion for the Call Up (cu) command
+#
+# More info:
+# `man zshcompsys`
+# http://www.linux-mag.com/id/1106/
+
+# Standard completion variables:
+local state  # set to a value when an argument action starts with `->`
+
+# Argument line format:
+# (option-exclusions)option[description]:Help-text-in-verbose-mode:action
+#
+# `option` can be followed by a symbol (e.g. `+`, `=`) to define how option
+# values can be written . Look up `_arguments` in the `zshcompsys` manpage.
+#
+# `action` can be blank, a list of values, or additional completion logic.
+#
+_arguments \
+  "-s+[baud rate]:Symbol transfer speed, depending on device:(9600)" \
+  "-l+[call-up line to listen to]:Device starting with 'cu':->line"
+
+case $state in
+  (line)
+    # `_files` is a general filepath completion helper
+    # `-W` = working directory
+    # `-g` = regexp filter
+    # All completion actions should return `0` on success and non-zero on error.
+    _files -W /dev -g 'cu\.*' && return 0
+    ;;
+esac

+ 3 - 0
zsh/zshrc

@@ -46,6 +46,9 @@ COMPLETION_WAITING_DOTS="true"
 # ZSH_CUSTOM=/path/to/new-custom-folder
 ZSH_CUSTOM=$HOME/dotfiles/zsh/custom
 
+# Custom completions
+fpath=($ZSH_CUSTOM/completions $fpath)
+
 # Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
 # Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
 # Example format: plugins=(rails git textmate ruby lighthouse)