From f298ebb2179eff947cdb9cb7a4bd96e9739eac5c Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Wed, 7 Mar 2018 21:34:05 +0000 Subject: [PATCH] Add shell completions and manpage * Add manpage Adds a basic manpage that was autogenerated with `help2man` and then slightly adjusted with information from the README.md and better formatting. * Add zsh completions Add completions for the zsh shell. These should be complete and even allow completion of the command inside `--command` and `-e`. * Add bash completions The bash completions are almost on the same level as the zsh completions. The only little thing the bash completions do not do is complete inside of `--command` and `-e`, instead bash just stops completion after these options. * Update readme with manpage and completions Added the install instructions for the manpage and completions to the README.md. Also tweaked the current readme a slight bit because the build section was structured in a slightly confusing way. --- README.md | 51 +++++++++++++++++++++++++-- alacritty-completions.bash | 58 +++++++++++++++++++++++++++++++ alacritty-completions.zsh | 23 +++++++++++++ alacritty.man | 70 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 199 insertions(+), 3 deletions(-) create mode 100644 alacritty-completions.bash create mode 100644 alacritty-completions.zsh create mode 100644 alacritty.man diff --git a/README.md b/README.md index 89b324b9..f2237098 100644 --- a/README.md +++ b/README.md @@ -213,6 +213,11 @@ filling in this section of the README. ### Building +**BEFORE YOU RUN IT:** Install the config file as described below; otherwise, +many things (such as arrow keys) will not work. + +#### Linux + Once all the prerequisites are installed, compiling Alacritty should be easy: ```sh @@ -220,10 +225,8 @@ cargo build --release ``` If all goes well, this should place a binary at `target/release/alacritty`. -**BEFORE YOU RUN IT:** Install the config file as described below; otherwise, -many things (such as arrow keys) will not work. -### Desktop Entry +##### Desktop Entry Many linux distributions support desktop entries for adding applications to system menus. To install the desktop entry for Alacritty, run @@ -233,6 +236,8 @@ sudo cp target/release/alacritty /usr/local/bin # or anywhere else in $PATH cp Alacritty.desktop ~/.local/share/applications ``` +#### MacOS + To build an application for macOS, run ```sh @@ -240,6 +245,46 @@ make app cp -r target/release/osx/Alacritty.app /Applications/ ``` +## Manual Page + +Installing the manual page requires the additional dependency `gzip`. +To install the manual page, run + +```sh +sudo mkdir -p /usr/local/share/man/man1 +gzip -c alacritty.man | sudo tee /usr/local/share/man/man1/alacritty.1.gz > /dev/null +``` + +## Shell completions + +To get automatic completions for alacritty's flags and arguments you can install the provided shell completions. + +### Zsh + +To install the completions for zsh, run + +``` +sudo cp alacritty-completions.zsh /usr/share/zsh/functions/Completion/X/_alacritty +``` + +### Bash + +To install the completions for bash, you can `source` the `alacritty-completions.bash` in your `~/.bashrc` file. + +If you do not plan to delete the source folder of alacritty, you can run + +```sh +echo "source $(pwd)/alacritty-completions.bash" >> ~/.bashrc +``` + +Otherwise you can copy it to the `~/.bash_completion` folder and source it from there: + +```sh +mkdir -p ~/.bash_completion +cp alacritty-completions.bash ~/.bash_completion/alacritty +echo "source ~/.bash_completion/alacritty" >> ~/.bashrc +``` + ## Configuration Although it's possible the default configuration would work on your system, diff --git a/alacritty-completions.bash b/alacritty-completions.bash new file mode 100644 index 00000000..57191515 --- /dev/null +++ b/alacritty-completions.bash @@ -0,0 +1,58 @@ +#/usr/bin/env bash + +# Load completion function +complete -F _alacritty alacritty + +# Completion function +_alacritty() +{ + local cur prev prevprev opts + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + prevprev="${COMP_WORDS[COMP_CWORD-2]}" + opts="-h --help -V --version --live-config-reload --no-live-config-reload --print-events -q -qq -v -vv -vvv --ref-test -e --command --config-file -d --dimensions -t --title --working-directory" + + # If `--command` or `-e` is used, stop completing + for i in "${!COMP_WORDS[@]}"; do + echo "${COMP_WORDS[i]}" >> ./testfile + if [[ "${COMP_WORDS[i]}" == "--command" ]] \ + || [[ "${COMP_WORDS[i]}" == "-e" ]] \ + && [[ "${#COMP_WORDS[@]}" -gt "$(($i + 2))" ]] + then + return 0 + fi + done + + # Make sure the Y dimension isn't completed + if [[ "${prevprev}" == "--dimensions" ]] || [[ "${prevprev}" == "-d" ]]; then + return 0 + fi + + # Match the previous word + case "${prev}" in + --command | -e) + # Complete all commands in $PATH + COMPREPLY=( $(compgen -c -- "${cur}") ) + return 0;; + --config-file) + # Path based completion + local IFS=$'\n' + compopt -o filenames + COMPREPLY=( $(compgen -f -- "${cur}") ) + return 0;; + --dimensions | -d | --title | -t) + # Don't complete here + return 0;; + --working-directory) + # Directory completion + local IFS=$'\n' + compopt -o filenames + COMPREPLY=( $(compgen -d -- "${cur}") ) + return 0;; + esac + + # Show all flags if there was no previous word + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 +} diff --git a/alacritty-completions.zsh b/alacritty-completions.zsh new file mode 100644 index 00000000..d2cc0eea --- /dev/null +++ b/alacritty-completions.zsh @@ -0,0 +1,23 @@ +#compdef alacritty + +_alacritty() { + local context curcontext="$curcontext" state line + typeset -A opt_args + + _arguments \ + "(-h --help)"{-h,--help}"[Prints help information]" \ + "(-V --version)"{-V,--version}"[Prints version information]" \ + "(--no-live-config-reload)--live-config-reload[Enable automatic config reloading]" \ + "(--live-config-reload)--no-live-config-reload[Disable automatic config reloading]" \ + "--print-events[Print all events to stdout]" \ + {-q,-qq}"[Reduces the level of verbosity (min is -qq)]" \ + {-v,-vv,-vvv}"[Increases the level of verbosity (max is -vvv)]" \ + "--ref-test[Generates ref test]" \ + "--config-file[Specify an alternative config file]:file:_files" \ + "(-d --dimensions)"{-d,--dimensions}"[Window dimensions]:dimensions:_guard '<->' width: :_guard '<->' length" \ + "--title[Defines the window title]:title:" \ + "--working-directory[Start shell in specified directory]:directory:_dir_list" \ + "(-e --command)"{-e,--command}"[Execute command (must be last arg)]:program: _command_names -e:*::program arguments: _normal" +} + +_alacritty "$@" diff --git a/alacritty.man b/alacritty.man new file mode 100644 index 00000000..31e2934e --- /dev/null +++ b/alacritty.man @@ -0,0 +1,70 @@ +.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.5. +.TH ALACRITTY "1" "March 2018" "alacritty 0.1.0" "User Commands" +.SH NAME +alacritty \- a cross-platform, gpu-accelerated terminal emulator +.SH "SYNOPSIS" +alacritty [FLAGS] [OPTIONS] +.SH DESCRIPTION +Alacritty is focused on simplicity and performance. +.TP +The performance goal means it should be faster than any other terminal emulator available. +.TP +The simplicity goal means that it doesn't have features such as tabs or splits (which can be better provided by a window manager or terminal multiplexer) nor niceties like a GUI config editor. +.SH "FLAGS" +.TP +\fB\-h\fR, \fB\-\-help\fR +Prints help information +.TP +\fB\-\-live\-config\-reload\fR +Enable automatic config reloading +.TP +\fB\-\-no\-live\-config\-reload\fR +Disable automatic config reloading +.HP +\fB\-\-print\-events\fR +.TP +\fB\-q\fR +Reduces the level of verbosity (the min level is \fB\-qq\fR) +.TP +\fB\-\-ref\-test\fR +Generates ref test +.TP +\fB\-v\fR +Increases the level of verbosity (the max level is \fB\-vvv\fR) +.TP +\fB\-V\fR, \fB\-\-version\fR +Prints version information +.SH "OPTIONS" +.TP +\fB\-e\fR, \fB\-\-command\fR ... +Command and args to execute (must be last argument) +.HP +\fB\-\-config\-file\fR +.IP +Specify alternative configuration file [default: $XDG_CONFIG_HOME/alacritty/alacritty.yml] +.HP +\fB\-d\fR, \fB\-\-dimensions\fR +.IP +Defines the window dimensions. Falls back to size specified by window manager if set to 0x0 [default: 80x24] +.TP +\fB\-t\fR, \fB\-\-title\fR +Defines the window title [default: Alacritty] +.TP +\fB\-\-working\-directory\fR <working\-directory> +Start the shell in the specified working directory +.SH "SEE ALSO" +See the alacritty github repository at https://github.com/jwilm/alacritty for the full documentation. +.SH "BUGS" +Found a bug? Please report it at https://github.com/jwilm/alacritty/issues. +.SH "AUTHORS" +Maintainers: +.sp +.RS 4 +.ie n \{\ +\h'-04'\(bu\h'+03'\c +.\} +.el \{\ +.sp -1 +.IP \(bu 2.3 +.\} +Joe Wilm <joe@jwilm.com>