Coder Social home page Coder Social logo

Fish shell support? about promptline.vim HOT 14 CLOSED

edkolev avatar edkolev commented on May 18, 2024
Fish shell support?

from promptline.vim.

Comments (14)

edkolev avatar edkolev commented on May 18, 2024

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

from promptline.vim.

mamiu avatar mamiu commented on May 18, 2024

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

from promptline.vim.

edkolev avatar edkolev commented on May 18, 2024

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.

from promptline.vim.

mamiu avatar mamiu commented on May 18, 2024

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

from promptline.vim.

edkolev avatar edkolev commented on May 18, 2024

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

from promptline.vim.

mamiu avatar mamiu commented on May 18, 2024

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!)

from promptline.vim.

edkolev avatar edkolev commented on May 18, 2024

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?

from promptline.vim.

edkolev avatar edkolev commented on May 18, 2024

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

untitled23222222

from promptline.vim.

mamiu avatar mamiu commented on May 18, 2024

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).

from promptline.vim.

lilyball avatar lilyball commented on May 18, 2024

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.

from promptline.vim.

mamiu avatar mamiu commented on May 18, 2024

@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.

from promptline.vim.

edkolev avatar edkolev commented on May 18, 2024

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 :)

from promptline.vim.

edkolev avatar edkolev commented on May 18, 2024

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

from promptline.vim.

AnderRasoVazquez avatar AnderRasoVazquez commented on May 18, 2024

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

Thank you =)

from promptline.vim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.