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

Limit prompt length automatically #190

Open
jamesquilty opened this issue Jul 22, 2022 · 0 comments
Open

Limit prompt length automatically #190

jamesquilty opened this issue Jul 22, 2022 · 0 comments

Comments

@jamesquilty
Copy link

jamesquilty commented Jul 22, 2022

I know others have raised the usability issues caused by having the full path of the current working directory as the rshell prompt. I have my terminal windows 80 columns wide, giving just enough room for two terminal windows side-by-side on my laptop. My working directories can be longer than 80 characters and the overlap this caused in rshell, along with the line munging reported in #152 (and noted in /main.py#L73-L75) was irritating me.

So, I wrote a quick loop which replaces the home directory part with ~ and then automatically trims the prompt if the directory part is still longer than [arbitrarily] 30 characters. The following change to line 1863 in the current HEAD revision on master should be made to enjoy a prompt that shows at the minimum the current directory name, even if its length is greater than 30 characters, and in all other cases displays a directory part of the prompt which is strictly 30 characters or less in length. It gives a prompt that looks like either ~/Hacks/rshell> or software/hacks/rshell>, which has been working well for me.

     def set_prompt(self):
         if self.stdin == sys.stdin:
-            prompt = PROMPT_COLOR + cur_dir + END_COLOR + '> '
+            prompt = cur_dir.replace(os.path.expanduser("~"), "~")
+            if len(prompt) > 30:
+                # Make the directory part of the prompt shorter!
+                head, prompt = os.path.split(prompt)
+                head, tail = os.path.split(head)
+                while len(os.path.join(tail, prompt)) <= 30:
+                    prompt = os.path.join(tail, prompt)
+                    head, tail = os.path.split(head)
+            prompt = PROMPT_COLOR + prompt + END_COLOR + '> '

I'd be happy to submit a pull request for this if it would be accepted.

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

1 participant