Skip to content
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

Fish shell support? #18

Closed
AnderRasoVazquez opened this issue Aug 19, 2014 · 14 comments
Closed

Fish shell support? #18

AnderRasoVazquez opened this issue Aug 19, 2014 · 14 comments

Comments

@AnderRasoVazquez
Copy link

Would be nice to have fish shell support.

Keep up the good work! =)

@edkolev
Copy link
Owner

edkolev commented Aug 21, 2014

Sorry, I won't be adding fish support -- it would basically require everything to be to re-implemented from scratch. You can see details here #16

Again, sorry to disappoint you

@edkolev edkolev closed this as completed Aug 21, 2014
@mamiu
Copy link

mamiu commented Aug 28, 2014

Would you implement fish support (e.g. a "fish" flag in :PromptlineSnapshot) if I port all the generated shell code to fish?

@edkolev
Copy link
Owner

edkolev commented Aug 29, 2014

Sure! I would suggest we start with one slice, function __promptline_cwd for example as it's the most often used one.

Could you port it to fish and share the code here? I will give some thought to what would be the best way to store the fish code in the repository.

@mamiu
Copy link

mamiu commented Aug 30, 2014

Ok, thanks! This implementation is only with awk, but I'll give a try with sed to compare the performance (I'm sorry but fish doesn't support native string manipulation till now).

function __promptline_cwd
    set -lx dir_limit "3"
    set -lx truncation "⋯ "
    set -lx first_char ""
    set -lx part_count 0
    set -lx formatted_cwd ""
    set -lx dir_sep "  "
    set -lx tilde "~"

    set -lx cwd (echo | awk "{pwd=\"$PWD\"; sub(\"$HOME\", \"~\", pwd); print pwd}")
    # get first char of the path, i.e. tilde or slash
    set -lx first_char (echo "$cwd" | awk '{print substr($0,0,1)}')

    # remove leading tilde
    set -lx cwd (echo | awk "{pwd=\"$cwd\"; sub(\"~\", \"\", pwd); print pwd}")

    while begin test (echo $cwd | awk '{print gsub(/\//,"")}') -gt 0; and test "$cwd" != "/"; end
        # pop off last part of cwd
        set -lx part (echo $cwd | awk -F'/' '{print $NF}')
        set cwd (echo $cwd  | awk -F'/' '{OFS="/";NF--;print $0;}')

        set formatted_cwd "$dir_sep$part$formatted_cwd"
        set part_count (echo (math part_count+1))

        if test "$part_count" = "$dir_limit"
            set first_char "$truncation"
            break
        end
    end

    printf "%s" "$first_char$formatted_cwd"
end

@edkolev
Copy link
Owner

edkolev commented Aug 30, 2014

Thanks!

Please don't do any performance optimizations for now. I'll try to come up with a decent way to keep the fish code in the repository. Will let you know when I have something working

@mamiu
Copy link

mamiu commented Aug 30, 2014

All right!
I think the easiest way for the users would be if we only check the file extension (e.g. :PromptlineSnapshot ~/.shell_prompt.fish airline). For the *.fish case you can set a variable fish and in the slices I'll check it to switch between shell and fish, because the fish code is so different from the shell code, that we have to seperate it from each other. (That's my opinion. Better proposals are always welcome!)

@edkolev
Copy link
Owner

edkolev commented Sep 1, 2014

After giving some thought to this, I think this might be a decent approach: instead of duplicating all the code in the repo and spawning tons of sed/awk/grep processes during runtime, just spawn one bash process to render the prompt.

This might seem a bit ugly at first, but could do the job pretty well I think: fish doesn't have much advanced scripting functionalities (which is it's design decision) so it would need some external tool to render the prompt. bash could be this "external tool", with something like:

function fish_prompt
  bash ~/.promptline.sh
end

I did a quick prototype and it seems quite functional... although there is some issue with colors/quoting.

Please let me know what you think of this approach. Do you see any pitfalls?

@edkolev
Copy link
Owner

edkolev commented Sep 1, 2014

Here's the prototype, colors & escaping is fixed here:

untitled23222222

@mamiu
Copy link

mamiu commented Sep 4, 2014

Your approach looks nice! Nevertheless I ported the shell code to fish and made (IMHO) some improvements. But you're right when you saying:

[...] duplicating all the code in the repo and spawning tons of sed/awk/grep processes
during runtime [...]

So firstly I don't wan't to integrate all the duplicated code into the repo, because I'm not sure if it would make sense to maintain the code twice (if you want, you can do it 😉) and secondly the bad string manipulation made me unhappy so I took care of it and now there is something happen (last comment from @kballard) at the fish-shell project. For now it's a little bit slow, but with the coming improvements I think it'll be fast like your version.

Here is the .promptline.fish and that's a little demo:

promptline

PS: I tested the script on Ubuntu 14.04 and OS X (10.9).

@lilyball
Copy link

lilyball commented Sep 5, 2014

I just commented on the gist with a rewritten version of __promptline_cmd that gets rid of most of the process spawning. I didn't directly compare the speeds (since I don't actually have Promptline installed; it's sitting on my to-do list), but it should be much faster.

@mamiu
Copy link

mamiu commented Sep 8, 2014

@kballard Thank you ever so much! I updated and commented the gist.

@AnderRasoVazquez If you are still interested in a fish version take a look at this gist.

@edkolev
Copy link
Owner

edkolev commented Sep 21, 2014

Great, thanks for sharing the gist! However, I'll stick with the approach I described above (fish will execute a bash script to get its prompt) as this would keep the codebase simpler. Once fish has string manipulation capabilities, I might revisit this topic.

Will let you know when fish support is added to promptline.

BTW sorry for the late response, I was away for a couple of weeks :)

@edkolev
Copy link
Owner

edkolev commented Sep 29, 2014

Support for fish is now added! @mamiu thank you very much!

@AnderRasoVazquez
Copy link
Author

This is great guys, I've followed the developing since beginning. Times like this makes open source great.

Thank you =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants