Skip to content

Commit 12d5f47

Browse files
committed
Add --no-hostname option
1 parent 6820e73 commit 12d5f47

File tree

5 files changed

+31
-7
lines changed

5 files changed

+31
-7
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ v0.7.0 (in development)
22
-----------------------
33
- The branch name/`HEAD` description is now truncated if it gets too long.
44
- Add `--theme` option for selecting between dark and light themes
5+
- Add `--no-hostname` option
56
- Drop support for Python 3.8
67

78
v0.6.0 (2024-05-12)

README.rst

+2
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ Options
113113
If running ``git status`` takes longer than the given number of
114114
seconds (default: 3), disable the Git integration
115115
116+
--no-hostname Do not include the local hostname in the prompt string
117+
116118
-T THEME, --theme THEME
117119
Select the theme to use for coloring prompt elements. The
118120
available themes are ``dark`` (the default, for use with light

src/jwodder_ps1/__main__.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ def main() -> None:
4343
" [default: 3]"
4444
),
4545
)
46+
parser.add_argument(
47+
"--no-hostname",
48+
action="store_true",
49+
help="Do not show the local hostname",
50+
)
4651
parser.add_argument(
4752
"-T",
4853
"--theme",
@@ -76,7 +81,9 @@ def main() -> None:
7681
else:
7782
s = ""
7883
else:
79-
s = PromptInfo.get(git=show_git, git_timeout=args.git_timeout).display(paint)
84+
s = PromptInfo.get(git=show_git, git_timeout=args.git_timeout).display(
85+
paint, hostname=not args.no_hostname
86+
)
8087
print(s)
8188

8289

src/jwodder_ps1/info.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def get(cls, git: bool = True, git_timeout: float = 3) -> PromptInfo:
9595
git=gs,
9696
)
9797

98-
def display(self, paint: Painter) -> str:
98+
def display(self, paint: Painter, hostname: bool = True) -> str:
9999
"""
100100
Construct & return a complete prompt string for the current environment
101101
"""
@@ -121,11 +121,11 @@ def display(self, paint: Painter) -> str:
121121
if self.venv_prompt is not None:
122122
ps1 += paint(f"({self.venv_prompt}) ", SC.VENV)
123123

124-
# Show the current hostname:
125-
ps1 += paint(self.hostname, SC.HOST)
126-
127-
# Separator:
128-
ps1 += ":"
124+
if hostname:
125+
# Show the current hostname:
126+
ps1 += paint(self.hostname, SC.HOST)
127+
# Separator:
128+
ps1 += ":"
129129

130130
# Show the path to the current working directory:
131131
ps1 += paint(self.cwdstr, SC.CWD)

test/test_info.py

+14
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,17 @@ def test_display_full_git_prompt_info_ansi_light() -> None:
107107
"\x1B[34m~/work\x1B[m"
108108
"@\x1B[32mmain\x1B[m$ "
109109
)
110+
111+
112+
def test_display_prompt_info_ansi_no_hostname() -> None:
113+
info = PromptInfo(
114+
mail=False,
115+
debian_chroot=None,
116+
conda_prompt_modifier=None,
117+
venv_prompt=None,
118+
hostname="firefly",
119+
cwdstr="~/work",
120+
git=None,
121+
)
122+
paint = Painter(ANSIStyler(), DARK_THEME)
123+
assert info.display(paint, hostname=False) == "\x1B[96m~/work\x1B[m$ "

0 commit comments

Comments
 (0)