-
Notifications
You must be signed in to change notification settings - Fork 5
Add shell completions for bash/fish/zsh and add executables to path #261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
|
@sthaeron You use zsh right? So would be good if you could test it for that |
|
Converted to draft since I was having some issues. When I try to pass a file it can't find it which is kind of a problem -- Handle file input, always need to define a file
inputFile :: Parser Input
inputFile =
InputFile
<$> strArgument
( metavar "INPUT"
<> help "Input filename"
<> action "file"
)When I run this in my normal bash it works fine, but when I run in Nix I get this is typically a problem when you are in a non-interactive shell so I am stuck troubleshooting that right now) |
| CMDLINE=(${CMDLINE[@]} --bash-completion-word $arg) | ||
| done | ||
|
|
||
| COMPREPLY=( $(/home/sam/Documents/IL2232/forsyde-devtools/dist-newstyle/build/x86_64-linux/ghc-9.10.2/forsyde-devtools-0.0.0.1/x/forsyde-devtools-exe/build/forsyde-devtools-exe/forsyde-devtools-exe "${CMDLINE[@]}") ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I guess it uses my "PWD" so it puts literally my path in there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yes. After replacing that with my own path it worked for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the intention is that you should re-generate this script by running
$ ./.completions/generate_completions.sh
inside NixOS from the root forsyde-devtools/. My general problem is that the wiki for optparse-applicative says the following:
For a quick test, you can run something like (for a program called foo on the PATH):
$ source <(foo --bash-completion-script `which foo`)Normally, the output of --bash-completion-script should be shipped with the program and copied to the appropriate directory (usually /etc/bash_completion.d/) during installation.
and I don't understand how I can ship this script with our project unless the binary is in like /usr/bin or something (since which resolves the path to something on my home path).
I can't really figure out how to get a PATH to our binary inside the bash completions that can calculate itself, that we can actually ship. Like do we literally have to put $(pwd) inside the completion scripts ourselves? I can put a command that runs the .completions/generate_completions.sh inside the Nix shell hook, but the issue is that we don't know if the binary exists yet when you do that (on first time clone of the repo I don't expect it to be built), so the which command would probably error out.
|
This is cool |
30913e0 to
f4c28c2
Compare
f4c28c2 to
152f38d
Compare
|
@sthaeron Now I have updated it so that you can autocomplete file paths for arguments, for both the compiler and LSP server. So this means that now you can do: (I mean you can technically also autocomplete the where it was previously not possible to autocomplete the path to the model. So we can leave this for now and revisit it once we have a real shippable binary. |
Yay I created shell completion! This adds the following:
forsyde-devtools-exeandforsyde-lsp-exetoPATH. This makes it so you can runforsyde-devtools-exedirectly without the usage ofcabal exec forsyde-devtools-exe --and having to manually type that out becausecabal execdoes not tab match.How it works
The file
/.completions/generate_completions.shis a bash script that generates completion scripts for bash/fish/zsh automatically. I created this since we might want to have this as a pre-commit hook or an automatic build task in the future so that we don't manually have to rerun it.Then, in the nix flake I use the following
where
$0retrieves the name of the current shell. This is where I am not entirely sure. If I run this in a "normal terminal" I get for instance:but if I run this inside
nix developI get:But if this can only be ran inside nix this should probably be fine? Then it should only be
bashorzshorfishwithout the/bin/part in front of it.Also, sorry, I couldn't help myself. I changed
chmod +x .git/hooks/*tochmod u+x .git/hooks/*and didn't undo it before I commited, I can edit it back if you want.Test
Start with
from the root of
forsyde-devtools. This should addforsyde-devtools-exeandforsyde-lsp-exetoPATH.Then, try to enter
forsyde-devtools-exeby typingwhich should automatically shell complete to
forsyde-devtools-exe.Try that this also works with:
which should automatically shell complete to
forsyde-lsp-exe.Then, try to complete some options in the executable such as
--output-forsyde-irwithwhich should complete to
forsyde-devtools-exe --output-forsyde-ir.Also, try that it works for the LSP with:
which should complete to
forsyde-lsp-exe --port.