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

Make Shell.prompt specifiable per-directory #7

Open
Spakman opened this issue Feb 28, 2011 · 2 comments
Open

Make Shell.prompt specifiable per-directory #7

Spakman opened this issue Feb 28, 2011 · 2 comments
Assignees
Milestone

Comments

@Spakman
Copy link
Owner

Spakman commented Feb 28, 2011

I'm not sure how best to implement this - POSIX extended attributes? Or a simple array of directories with corresponding prompts in .urchin.rb.

@brandondrew
Copy link

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.

@Spakman
Copy link
Owner Author

Spakman commented Oct 2, 2012

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.

@Spakman Spakman self-assigned this Jul 8, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants