Repository: pypa/virtualenv

Issue:
`--prompt .` : the dot causes the basename of the current directory to be used
**What's the problem this feature will solve?**
<!-- What are you trying to do, that you are unable to achieve with pip as it currently stands? -->
I'd like an easy way to have the prompt reflect the directory the env was created in.

**Describe the solution you'd like**
<!-- Clear and concise description of what you want to happen. -->
I'd like `--prompt .` to use the basename of the current directory for the prompt, similar to what venv does. 
More specifically, the prompt should be the directory in parentheses. 

<!-- Provide examples of real world use cases that this would enable and how it solves the problem described above. -->
```bash
$ mkdir foo
$ cd foo
$ virtualenv venv --prompt .
$ source venv/bin/activate
(foo) $ 
```

**Alternative Solutions**
<!-- Have you tried to workaround the problem using pip or other tools? Or a different approach to solving this issue? Please elaborate here. -->
We could change the default prompt to be this. that'd be cool. 

**Additional context**
<!-- Add any other context, links, etc. about the feature here. -->
This as been in the venv implementation of Pyhon since Python 3.9.something.

Python 3 documentation: https://docs.python.org/3/library/venv.html#api 

> prompt – a String to be used after virtual environment is activated (defaults to None which means directory name of the environment would be used). _If the special string "." is provided, the basename of the current directory is used as the prompt._



Discussion:
If anyone puts in a PR with tests I'd be happy to accept, merge and release it. Thanks!
I could attempt a PR, unless you were planning on working on it @okken?
@rkm Go for it. I'd love to see it implemented.

Resolving patch:
diff --git a/src/virtualenv/activation/activator.py b/src/virtualenv/activation/activator.py
--- a/src/virtualenv/activation/activator.py
+++ b/src/virtualenv/activation/activator.py
@@ -1,5 +1,6 @@
 from __future__ import absolute_import, unicode_literals
 
+import os
 from abc import ABCMeta, abstractmethod
 
 from six import add_metaclass
@@ -14,7 +15,7 @@ def __init__(self, options):
 
         :param options: the parsed options as defined within :meth:`add_parser_arguments`
         """
-        self.flag_prompt = options.prompt
+        self.flag_prompt = os.path.basename(os.getcwd()) if options.prompt == "." else options.prompt
 
     @classmethod
     def supports(cls, interpreter):
diff --git a/src/virtualenv/run/plugin/activators.py b/src/virtualenv/run/plugin/activators.py
--- a/src/virtualenv/run/plugin/activators.py
+++ b/src/virtualenv/run/plugin/activators.py
@@ -43,7 +43,10 @@ def handle_selected_arg_parse(self, options):
             "--prompt",
             dest="prompt",
             metavar="prompt",
-            help="provides an alternative prompt prefix for this environment",
+            help=(
+                "provides an alternative prompt prefix for this environment "
+                "(value of . means name of the current working directory)"
+            ),
             default=None,
         )
         for activator in self.active.values():


Test patch:
diff --git a/tests/unit/activation/test_activator.py b/tests/unit/activation/test_activator.py
new file mode 100644
--- /dev/null
+++ b/tests/unit/activation/test_activator.py
@@ -0,0 +1,18 @@
+from __future__ import absolute_import, unicode_literals
+
+from argparse import Namespace
+
+from virtualenv.activation.activator import Activator
+
+
+def test_activator_prompt_cwd(monkeypatch, tmp_path):
+    class FakeActivator(Activator):
+        def generate(self, creator):
+            raise NotImplementedError
+
+    cwd = tmp_path / "magic"
+    cwd.mkdir()
+    monkeypatch.chdir(cwd)
+
+    activator = FakeActivator(Namespace(prompt="."))
+    assert activator.flag_prompt == "magic"