-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:cmcgee1024/swiftly into self-host-g…
…h-actions
- Loading branch information
Showing
8 changed files
with
182 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Add Shell Auto-completions | ||
|
||
Swiftly can generate shell auto-completion scripts for your shell to automatically complete subcommands, arguments, options and flags. It does this using the [swift-argument-parser](https://apple.github.io/swift-argument-parser/documentation/argumentparser/installingcompletionscripts/), which has support for Bash, Z shell, and Fish. | ||
|
||
You can ask swiftly to generate the script using the hidden `--generate-completion-script` flag with the type of shell like this: | ||
|
||
``` | ||
swiftly --generate-completion-script <shell> | ||
``` | ||
|
||
@TabNavigator { | ||
@Tab("zsh") { | ||
If you have [oh-my-zsh](https://ohmyz.sh/) installed then this command will install the swiftly completions into the default directory: | ||
|
||
``` | ||
swiftly --generate-completion-script zsh > ~/.oh-my-zsh/completions/_swiftly | ||
``` | ||
|
||
Otherwise, you'll need to add a path for completion scripts to your function path, and turn on completion script autoloading. First, add these lines to ~/.zshrc: | ||
|
||
``` | ||
fpath=(~/.zsh/completion $fpath) | ||
autoload -U compinit | ||
compinit | ||
``` | ||
|
||
Next, create the completion directory and add the swiftly completions to it: | ||
|
||
``` | ||
mkdir -p ~/.zsh/completion && swiftly --generate-completion-script zsh > ~/.zsh/completions/swiftly | ||
``` | ||
} | ||
|
||
@Tab("bash") { | ||
If you have [bash-completion](https://github.com/scop/bash-completion) installed then this command will install the swiftly completions into the default directory: | ||
|
||
``` | ||
swiftly --generate-completion-script bash > swiftly.bash | ||
# copy swiftly.bash to /usr/local/etc/bash_completion.d | ||
``` | ||
|
||
Without bash-completion create a directory for the completion and generate the script in there: | ||
|
||
``` | ||
mkdir -p ~/.bash_completions && swiftly --generate-completion-script bash > ~/.bash_completions/swiftly.bash | ||
``` | ||
|
||
Add a line to source that script in your `~/.bash_profile` or `~/.bashrc` file: | ||
|
||
``` | ||
source ~/.bash_completions/swiftly.bash | ||
``` | ||
} | ||
|
||
@Tab("fish") { | ||
Generate the completion script to any path in the environment variable `$fish_completion_path`. Typically this command will generate the script in the right place: | ||
|
||
``` | ||
swiftly --generate-completion-script fish > ~/.config/fish/completions/swiftly.fish | ||
``` | ||
} | ||
} | ||
|
||
Once you have installed the completions you can type out a swiftly command, and press a special key (e.g. tab) and the shell will show you the available subcommand, argument, or options to make it easier to assemble a working command-line. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/bin/sh | ||
|
||
PREFIX=${MUSL_PREFIX:-"/usr/local/musl"} | ||
if [ ! -d "${PREFIX}" ]; then | ||
echo "invalid prefix: ${PREFIX}" | ||
return 1 | ||
fi | ||
|
||
CLANG=${REALCLANG:-"clang"} | ||
|
||
hasNo() { | ||
pat="$1" | ||
shift 1 | ||
|
||
for e in "$@"; do | ||
if [ "$e" = "${pat}" ]; then | ||
return 1 | ||
fi | ||
done | ||
return 0 | ||
} | ||
|
||
ARGS="-nostdinc" | ||
TAIL="" | ||
|
||
if hasNo '-nostdinc' "$@"; then | ||
ARGS="${ARGS} -isystem ${PREFIX}/include" | ||
fi | ||
|
||
if \ | ||
hasNo '-c' "$@" && \ | ||
hasNo '-S' "$@" && \ | ||
hasNo '-E' "$@" | ||
then | ||
ARGS="${ARGS} -nostdlib" | ||
ARGS="${ARGS} -Wl,-dynamic-linker=${PREFIX}/lib/libc.so" | ||
ARGS="${ARGS} -L${PREFIX}/lib -L${PREFIX}/lib/swift/clang/lib/linux" | ||
|
||
if hasNo '-nostartfiles' "$@" && \ | ||
hasNo '-nostdlib' "$@" && \ | ||
hasNo '-nodefaultlibs' "$@" | ||
then | ||
ARGS="${ARGS} ${PREFIX}/lib/crt1.o" | ||
ARGS="${ARGS} ${PREFIX}/lib/crti.o" | ||
|
||
TAIL="${TAIL} ${PREFIX}/lib/crtn.o" | ||
fi | ||
|
||
if hasNo '-nostdlib' "$@" && \ | ||
hasNo '-nodefaultlibs' "$@" | ||
then | ||
TAIL="${TAIL} -lc -lclang_rt.builtins-$(uname -m)" | ||
fi | ||
fi | ||
|
||
exec ${CLANG} ${ARGS} "$@" ${TAIL} -static | ||
|