如何强制bash自动完成到一个命令?

时间:2009-10-09 01:28:44

标签: linux bash shell autocomplete

我刚刚升级到Ubuntu Karmic 9.10并且现在很强大。 问题是em-TAB-不再自动完成emacs ...

我有一种方法可以让我的Bourne-Shell完成em-TAB-总是发送给emacs吗?

谢谢

2 个答案:

答案 0 :(得分:4)

如果您为em添加了.bashrc的别名,则可以一起跳过Tab-completion:

alias em=emacs

使用此功能,只需输入命令em即可启动emacs。

答案 1 :(得分:2)

我使用另一种方法 - 简单的 e 命令:

#!/bin/sh

# Written by Oleksandr Gavenko , 2008.
# File placed by author in public domain.

# View file in emacs buffer using emacsclient.
# If emacs not already running, run it.
# Put this file 'e' in your PATH.
# Name `e' because `edit'.

case "$1" in
  -h|-help|--help)
    echo "Emacsclient run script."
    echo "Usage:"
    echo "  e [-h|--help] file..."
    exit 0
    ;;
  "")
    echo "What file you want to open?"
    exit 0
    ;;
esac

if [ -n "$COMSPEC" ]; then
  # We probably under Windows like OS. I like native Emacs over Cygwin.
  for arg; do
    emacsclientw -a emacs -n "$arg"
  done
else
  # We under UNIX like OS.
  for arg; do
    emacsclient -a emacs -n "$arg"
  done
fi

我也在MS Windows的批处理文件(.bat)语言中编写类似的脚本:

@echo off

REM Written by Oleksandr Gavenko , 2008.
REM File placed by author in public domain.

REM View files in emacs buffer using emacsclientw.
REM If emacs not already running, run it.
REM Put this file (e.bat) in your PATH.
REM Name `e' because `edit'.

REM If path to file contain spaces it must be inclosed into quotes.

if x%1 == x-h     goto usage
if x%1 == x-help  goto usage
if x%1 == x--help goto usage

:loop
emacsclientw -a runemacs -n %1
shift
if not x%1 == x goto loop
goto :eof

:usage
@echo Alias for emacsclient without waiting for editing ending.
@echo Usage:
@echo   e [-h^|--help] file...