Comments (14)
Ion definitely does look interesting, but I'm not familiar with the syntax. Is there a mechanism for prompt/pwd hooks?
If you can make a PR adding Ion support, I would be happy to merge it!
from zoxide.
@ajeetdsouza I have no idea what to do if a user supplied a fn PROMPT
function, maybe encourage the user to work with the variable instead.
Another problem aside from the variadic functions is this:
For me in ion echo $(zoxide query -i)
and echo $(fzf)
don't interactively print to the terminal. It is executing in the background and after entering a string and pressing enter you get the result but I wouldn't call that interactive.
echo $(sk)
this works interactively. sk is basically a rust version of fzf
A this point I also think that it is problematic to implement ion support. For the ones that are interested in ion, at this point in time they should probaly put this manually into their shell.
from zoxide.
ion currently does not allow functions to be called with different numbers of args, unless the args are passed in as an array. So in practice, you'd need to write z [ query ]
instead of z query
.
With that caveat, here is an ion
script that would be equivalent to the output of zoxide init
for other shells:
fn _z_cd argv:[str]
cd @argv
exists -s _ZO_ECHO && echo $PWD
end
fn z argv:[str]
match @argv
case [ - ]
_z_cd [ @argv ]
case _
let result = $(zoxide query @argv)
if test -d $result
_z_cd [ $result ]
else if test -n $result
echo $result
end
end
end
alias zi='z -i'
alias za='zoxide add'
alias zq='zoxide query'
alias zr='zoxide remove'
Adding a hook that calls zoxide add
would require adding zoxide add
to the fn PROMPT
function definition, which is how ion lets users customize their prompt. Not sure how one would set that hook up by running eval $(zoxide init ion)
, best is probably to ask users to add zoxide add
to their PROMPT by hand. There is also no way to call zoxide add
when PWD
gets modified, as far as I can tell.
from zoxide.
Let me summarize what to implement in the ion REPL as a sort of plan, once we get the grammar formally defined and the parser rewritten in a more robust way.
I would like to enforce readability in scripts, but I am not sure how to archive this at best without exploding complexity.
- REPL must differentiate between status line, cursor symbol and cursor field.
- Ideally REPL can properly handle background processes with counters, so one does not need ugly hacks. (Background processes are currently broken.)
- I think hooks are a poor abstraction, when you know when things will happen. When we get working function returns, pwd can be used with the path before and after changing directories.
- Aliased functions (of the initrc and other sourced files) must start with capital letters, if they are needed (I am not convinced yet).
from zoxide.
Hm, doesn't the absence of
let
implymut
? Or has it been added to make mutations more explicit?
let
can shadow variables in functions, like in the following:
let var:int = 1;
let stuff:int = 2;
fn testme
let var:int = 3;
mut stuff = 42;
echo $var
end
testme
echo $var
echo $stuff
3
1
42
We could also use local
etc, but thats too long and variables should be ALWAYS local (or explicitly written global environment variables).
from zoxide.
I'm closing this issue for now. The related Ion issue (https://gitlab.redox-os.org/redox-os/ion/-/issues/834) has been open 4 years without a conclusion, so it's unlikely we'll be able to support it in the near future.
Feel free to reopen / create a new issue once Ion adds enough functionality / stability to support something like this.
from zoxide.
@kolia I had a look at ion
today. I'm not a fan of changing the z
syntax specially for ion
, and having the user specifically add zoxide add
to their shell also seems less-than-ideal.
However, given that ion
doesn't try to imitate POSIX in any way, I can understand this. There doesn't appear to be a better way to do this at the moment either, and your implementation does work well - so do feel free to create a PR with these changes!
from zoxide.
Sure I could make a PR.
I’ve also opened an issue for ion https://gitlab.redox-os.org/redox-os/ion/issues/962, alternatively we could wait and see if someone picks up on it.
from zoxide.
Yes, I too think waiting is a good idea for now. We can pick this up later if they decide against implementing variadic functions.
Thank you for your work on this!
from zoxide.
@kolia @ajeetdsouza regarding the issue of adding the _zoxide_hook
to the HOOK_PROMPT
one solution that currently works for me is
fn _zoxide_hook
zoxide add
end
if not matches $PROMPT '.*?_zoxide_hook.*?'
let PROMPT ::= "\$(_zoxide_hook)"
end
from zoxide.
@ahkrr, from what I've read, PROMPT
could either be a variable or a function, so both cases need to be handled.
from zoxide.
Hey @matu3ba, thanks for the update!
I think hooks are a poor abstraction
How so? I didn't exactly understand the alternative you proposed, could you elaborate?
I am not sure how to achieve this at best without exploding complexity
Admittedly, designing a shell is much harder than designing a programming language, because you have to ensure that it's easy enough for anyone to read/write, concise enough to be able to do a lot of work in a single line of code, and yet powerful enough to write scripts with.
I have no experience with programming language design, but I'm interested - could you explain why the mut
keyword was introduced, and why references are necessary?
from zoxide.
Hey @matu3ba, thanks for the update!
I think hooks are a poor abstraction
How so? I didn't exactly understand the alternative you proposed, could you elaborate?
You want to (over)write the shell configuration to have defined entry- and exit-points from what the shell is doing (on user keypress), since that is way simpler, has less delay etc.
I am not sure how to achieve this at best without exploding complexity
Admittedly, designing a shell is much harder than designing a programming language, because you have to ensure that it's easy enough for anyone to read/write, concise enough to be able to do a lot of work in a single line of code, and yet powerful enough to write scripts with.
And fast for the use case (batch processing = nu or individual processing = ion). Other shells use more tradeoffs (zsh, bash etc), but are still complex beasts. Or they are okay with being slower (fish). Dash is comparable (with less functionality), but it is very difficult to safely optimise C code (and you get some parsing+evaluation overhead of POSIX shell requirements).
I have no experience with programming language design, but I'm interested - could you explain why the
mut
keyword was introduced, and why references are necessary?
Copy-assign is always slower, since you need to allocate a not efficiently precomputable space (depends on context of execution). Hence you want mut
and for safe usage of other accessible scopes references for functions.
Personally, I would also like to restrict the access to other scopes, but that are some rules for the longer future to do. And thats too slow+complex to do in every parsing for execution. Another, way simpler, parser could be used for that.
from zoxide.
Hm, doesn't the absence of let
imply mut
? Or has it been added to make mutations more explicit?
from zoxide.
Related Issues (20)
- Add support for kornshell HOT 7
- Conflict between zoxide, zsh-autocomplete, and fzf results in erroneous behavior HOT 1
- Support the `--` command-line argument HOT 4
- Interactive mode (space + tab) doesn't appear to be working on macOS HOT 5
- Interactive expansion doesn't work as expected when it matches a single entry then echos command 3 times HOT 6
- How can I change the shortcuts in zi?
- zoxide: no match found on startup HOT 10
- Possible to get a list of previous dirs by time?
- feasibility integrate with vscode cli(`code`) HOT 3
- unknown option: --keep-right zoxide: fzf returned an error HOT 1
- Unable to initialize zoxide in my zsh HOT 2
- Zoxide with cd alias breaks fish - 'prevd-or-backward-word' & 'nextd-or-forward-word'
- eval not found HOT 5
- Unable to install zoxide in arch linux HOT 2
- Arch 'MANJARO' with ZSH and Powerlevel10k PROBLEMS HOT 1
- Help with excluding dirs HOT 2
- z "" should act as z with no arguments (go to home directory) HOT 3
- Feature request: "z . some keywords" to find matches in current directory HOT 2
- New Command Idea: Env
- Zoxide "zi" hangs when mount point is in list (/mnt) that's unavailable HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zoxide.