Skip to content

Commit

Permalink
Add initial shell completion
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitabobko committed May 26, 2024
1 parent 7eb822d commit 296f8bc
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 5 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ jobs:
- name: Checkout
uses: actions/checkout@v3
- name: Install deps
run: brew install xcodegen gsed asciidoctor swiftlint
run: |
brew install xcodegen gsed asciidoctor xcbeautify swiftlint bash fish wget
./script/install-complgen.sh
- uses: actions/cache@v3
with:
path: .bin
key: ${{ runner.os }}-${{ runner.arch }}
- name: Build Debug
# "-" means "Sign to run locally". There is no aerospace-codesign-certificate in GH Actions
run: ./build-debug.sh --codesign-identity -
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/.idea
/.debug
/.release
/.shell-completion
/.site
/.bin
/.man
# IDK, AppCode randomly creates this EMPTY file. I have no idea what this is
/default.profraw
Expand Down
97 changes: 97 additions & 0 deletions args-grammar.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# EBNF-like grammar of aerospace CLI args to generate shell completion. Managed by https://github.com/adaszko/complgen
aerospace <subcommand>;

<subcommand> ::= close [--quit-if-last-window]

| close-all-windows-but-current [--quit-if-last-window]

| enable (on|off|toggle)

| flatten-workspace-tree

| <focus-subcommand>

| focus-monitor [--wrap-around] (left|down|up|right) | focus-monitor (left|down|up|right) [--wrap-around]
| focus-monitor [--wrap-around] (next|prev) | focus-monitor (next|prev) [--wrap-around]
| focus-monitor <monitor-pattern>...

| join-with (left|down|up|right)

| layout (h_tiles|v_tiles|h_accordion|v_accordion|tiles|accordion|horizontal|vertical|tiling|floating)...

| macos-native-fullscreen [on|off]

| macos-native-minimize

| mode <binding-mode>

| move (left|down|up|right)

| move-node-to-monitor [--wrap-around] (left|down|up|right) | move-node-to-monitor (left|down|up|right) [--wrap-around]
| move-node-to-monitor [--wrap-around] (next|prev) | move-node-to-monitor (next|prev) [--wrap-around]
| move-node-to-monitor <monitor-pattern>...

| move-node-to-workspace [--wrap-around] (next|prev) | move-node-to-workspace (next|prev) [--wrap-around]
| move-node-to-workspace <workspace>

| move-workspace-to-monitor [--wrap-around] (next|prev) | move-workspace-to-monitor (next|prev) [--wrap-around]

| reload-config [--no-gui] [--dry-run] | reload-config [--dry-run] [--no-gui]

| resize (smart|width|height) [+|-]<number>

| split (horizontal|vertical|opposite)

| trigger-binding <binding> --mode <mode-id> | trigger-binding --mode <mode-id> <binding>

| workspace [--auto-back-and-forth] <workspace> | workspace <workspace> [--auto-back-and-forth]
| workspace [--wrap-around] (next|prev) | workspace (next|prev) [--wrap-around]

| workspace-back-and-forth

| config --get <config-key> [--son|--keys]... | config [--json|--keys]... --get <config-key>
| config --major-keys
| config --all-keys
| config --config-path

| debug-windows

| list-apps [--macos-native-hidden [no]]

| list-exec-env-vars

| list-monitors [--focused [no]] [--mouse [no]] | list-monitors [--mouse [no]] [--focused [no]]

| <list-windows-subcommand>

| list-workspaces --monitor <monitor-id>... [--visible [no]] [--empty [no]]
| list-workspaces --monitor <monitor-id>... [--empty [no]] [--visible [no]]
| list-workspaces --all
| list-workspaces --focused
;

<window-id> ::= {{{ aerospace list-windows --all --format "%{window-id}%{right-padding}%{tab}%{app-name}%{right-padding} | %{window-title}" }}};
<binding> ::= {{{ aerospace config --get mode --keys | xargs -I{} aerospace config --get mode.{}.binding --keys }}};
<mode-id> ::= {{{ aerospace config --get mode --keys }}};
<binding-mode> ::= <mode-id>;
<workspace> ::= {{{ aerospace list-workspaces --monitor all --empty no }}};
<config-key> ::= {{{ aerospace config --all-keys }}};
<number> ::= {{{ true }}};
<monitor-pattern> ::= {{{ true }}};

<focus-subcommand> ::=
focus [<focus-flag>]... (left|down|up|right) [<focus-flag>]... |
focus --window-id <window-id>;
<focus-flag> ::= --boundaries <boundary>|--boundaries-actions <boundaries-action>;
<boundaries-action> ::= stop|wrap-around-the-workspace|wrap-around-all-monitors;
<boundary> ::= workspace|all-monitors-outer-frame;

<list-windows-subcommand> ::=
list-windows [<list-windows-filter-flag>]... |
list-windows --all |
list-windows --focused;
<list-windows-filter-flag> ::= --workspace <workspace-or-special>... | --monitor <monitor-id>... | --pid <pid> | --app-id <app-id>;
<workspace-or-special> ::= visible | focused | <workspace>;
<app-id> ::= {{{ true }}}; # todo
<pid> ::= {{{ true }}}; # todo
<monitor-id> ::= all | mouse | focused; # todo
2 changes: 2 additions & 0 deletions build-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ EOF
#############

./build-docs.sh
./build-shell-completion.sh

./generate.sh
./script/check-uncommitted-files.sh
Expand Down Expand Up @@ -115,6 +116,7 @@ codesign -v .release/aerospace
############

mkdir -p .release/AeroSpace-v$build_version/manpage && cp .man/*.1 .release/AeroSpace-v$build_version/manpage
cp -r .shell-completion .release/AeroSpace-v$build_version/shell-completion
cd .release
mkdir -p AeroSpace-v$build_version/bin && cp -r aerospace AeroSpace-v$build_version/bin
cp -r AeroSpace.app AeroSpace-v$build_version
Expand Down
20 changes: 20 additions & 0 deletions build-shell-completion.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
cd "$(dirname "$0")"
source ./script/setup.sh

./script/install-complgen.sh

rm -rf .shell-completion && mkdir -p \
.shell-completion/zsh \
.shell-completion/fish \
.shell-completion/bash

${complgen} aot args-grammar.conf \
--zsh-script .shell-completion/zsh/_aerospace 2>&1 \
--fish-script .shell-completion/fish/aerospace.fish 2>&1 \
--bash-script .shell-completion/bash/aerospace 2>&1

# Check basic syntax
zsh -c 'autoload -Uz compinit; compinit; source ./.shell-completion/zsh/_aerospace'
fish -c 'source ./.shell-completion/fish/aerospace.fish'
bash -c 'source ./.shell-completion/bash/aerospace'
9 changes: 7 additions & 2 deletions dev-docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ The dependencies that are required to build AeroSpace:
- [XcodeGen](https://github.com/yonaskolb/XcodeGen)
- [xcbeautify](https://github.com/cpisciotta/xcbeautify)
- [GNU sed](https://www.gnu.org/software/sed/)
- [wget](https://www.gnu.org/software/wget/)
- [Asciidoctor](https://asciidoctor.org/)
- [SwiftLint](https://github.com/realm/SwiftLint)
- Shell completion
- [bash](https://www.gnu.org/software/bash/)
- [fish](https://fishshell.com/)

```bash
brew install xcodegen gsed asciidoctor xcbeautify swiftlint
```shell
brew install xcodegen gsed asciidoctor xcbeautify swiftlint bash fish wget
```

## 2. Create codesign certificate
Expand All @@ -42,6 +46,7 @@ Signing the binary is required to preserve accessibility permission across rebui
- `run-debug.sh` - Run debug build of AeroSpace.app. It might be better to run debug build from Xcode.
- `run-cli.sh` - Run `aerospace` in CLI. Arguments are forwarded to `aerospace` binary
- `build-docs.sh` - Build the site and manpages to `.site` and `.man` dirs respectively
- `build-shell-completion.sh` - Build shell completion to `.shell-completion`
- `generate.sh` - Regenerate generated project files. `AeroSpace.xcodeproj` is generated, and some of the source files
(the source files have `Generated` suffix in their names)

Expand Down
2 changes: 2 additions & 0 deletions docs/guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ https://brew.sh/[Homebrew] is a package manager for macOS
brew install --cask nikitabobko/tap/aerospace
----

If you want shell completion to work (optional), you need to configure your shell to enable completion provided by homebrew packages: https://docs.brew.sh/Shell-Completion

[#manual-installation]
=== Manual installation

Expand Down
18 changes: 18 additions & 0 deletions script/install-complgen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
cd "$(dirname "$0")/.."
source ./script/setup.sh

complgen_version="v0.1.8"
export complgen="./.bin/complgen-${complgen_version}-$(arch)"
if ! [ -f "$complgen" ]; then
rm -rf .bin && mkdir -p .bin
if [ "$(arch)" = arm64 ]; then
wget -O "$complgen" "https://github.com/adaszko/complgen/releases/download/${complgen_version}/complgen-aarch64-apple-darwin"
elif [ "$(arch)" = i386 ]; then
wget -O "$complgen" "https://github.com/adaszko/complgen/releases/download/${complgen_version}/complgen-x86_64-apple-darwin"
else
echo "Unknown architecture $(arch)" > /dev/stderr
exit 1
fi
chmod +x "$complgen"
fi
12 changes: 10 additions & 2 deletions script/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@ set -o pipefail # Any command failed in the pipe fails the whole pipe
# set -x # Print shell commands as they are executed (or you can try -v which is less verbose)

setup() {
BREW_PREFIX="$(brew --prefix)"
export BREW_PREFIX="$(brew --prefix)"
tmp=(
${BREW_PREFIX}/opt/asciidoctor/bin
${BREW_PREFIX}/opt/gsed/libexec/gnubin
${BREW_PREFIX}/opt/tree/bin
${BREW_PREFIX}/opt/xcodegen/bin
${BREW_PREFIX}/opt/xcbeautify/bin
${BREW_PREFIX}/opt/swiftlint/bin
${BREW_PREFIX}/opt/fishfish/bin
${BREW_PREFIX}/opt/bash/bin
${BREW_PREFIX}/opt/wget/bin
/bin # bash
/usr/bin # xcodebuild, zip
/usr/bin # xcodebuild, zip, arch
)

IFS=':'
Expand All @@ -29,6 +32,11 @@ fi

brew() { "${BREW_PREFIX}/bin/brew" "$@"; }

if ! [ -f ${BREW_PREFIX}/opt/bash/bin/bash ]; then
echo "Please install bash from homebrew" > /dev/stderr
exit 1
fi

xcodebuild() {
# Mute stderr
# 2024-02-12 23:48:11.713 xcodebuild[60777:7403664] [MT] DVTAssertions: Warning in /System/Volumes/Data/SWE/Apps/DT/BuildRoots/BuildRoot11/ActiveBuildRoot/Library/Caches/com.apple.xbs/Sources/IDEFrameworks/IDEFrameworks-22269/IDEFoundation/Provisioning/Capabilities Infrastructure/IDECapabilityQuerySelection.swift:103
Expand Down

0 comments on commit 296f8bc

Please sign in to comment.