You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm picturing wanting to make simple modifications on a per-directory basis, rather than having to define the entire prompt separately for each directory (or group of directories). Would it be too awkward to sub-class per directory, so that you could just modify the bits you want different for that directory? Maybe something like this... the to_s method would be the main thing that defined the prompt, and then you could add as many other methods as you wanted the various items you wanted to appear in the prompt. The main class could ship with Urchin and you could either use open classes to change parts, or just subclass it for your own prompts, or both.
class Urchin::Prompt
def ending
">: "
end
def current_directory
`pwd`
end
def to_s
"#{current_directory} #{ending}"
end
end
class HomePrompt < Urchin::Prompt
def current_directory
`pwd`.gsub(`$HOME`, '~')
end
end
Sorry the example is contrived and not very useful.
Thanks a lot for the example. The more I think about it, the more I agree that having some way to share and extend prompt behaviours would be very useful.
As it stands, a prompt definition is simply a Proc that is run as we display the prompt. Although I don't plan to work on the per-directory things until after version 0.2 is out, we will need some way to encapsulate things so perhaps breaking out a Prompt class sooner is a good idea.
I'm not sure how best to implement this - POSIX extended attributes? Or a simple array of directories with corresponding prompts in .urchin.rb.
The text was updated successfully, but these errors were encountered: