File tree Expand file tree Collapse file tree 6 files changed +42
-8
lines changed Expand file tree Collapse file tree 6 files changed +42
-8
lines changed Original file line number Diff line number Diff line change @@ -666,7 +666,7 @@ jobs:
666
666
shell : powershell
667
667
- name : Test CMD shell failure
668
668
run : |
669
- uv run pytest ./tests/shellcompletion/test_shell_resolution.py::test_get_win_shell_failure
669
+ uv run pytest --cov-append ./tests/shellcompletion/test_shell_resolution.py::test_get_win_shell_failure
670
670
shell : cmd
671
671
- name : Store coverage files
672
672
uses : actions/upload-artifact@v4
Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ Change Log
7
7
v3.1.0 (2024-03-xx)
8
8
===================
9
9
10
+ * Fixed `fish completion installs should respect XDG_CONFIG_HOME <https://github.com/django-commons/django-typer/issues/193 >`_
11
+ * Fixed `zsh completion installs should respect ZDOTDIR <https://github.com/django-commons/django-typer/issues/192 >`_
10
12
* Implemented `Support Django 5.2 <https://github.com/django-commons/django-typer/issues/188 >`_
11
13
* Implemented `Switch poetry -> uv <https://github.com/django-commons/django-typer/issues/185 >`_
12
14
* Implemented `Require tests to pass before release action runs. <<https://github.com/django-commons/django-typer/issues/173> `_
Original file line number Diff line number Diff line change @@ -237,6 +237,14 @@ def uninstall(self):
237
237
Deriving classes must implement this method to uninstall the completion script.
238
238
"""
239
239
240
+ @abstractmethod
241
+ def get_user_profile (self ) -> Path :
242
+ """
243
+ Most shells have a profile script that is sourced when the interactive shell
244
+ starts. Deriving classes should implement this method to return the location
245
+ of that script.
246
+ """
247
+
240
248
def process_rich_text (self , text : str ) -> str :
241
249
"""
242
250
Removes rich text markup from a string if color is disabled, otherwise it
Original file line number Diff line number Diff line change @@ -41,9 +41,15 @@ class BashComplete(DjangoTyperShellCompleter):
41
41
by default.
42
42
"""
43
43
44
+ def get_user_profile (self ) -> Path :
45
+ """
46
+ Get .bashrc it is always located in the user's home directory.
47
+ """
48
+ return Path .home () / ".bashrc"
49
+
44
50
@cached_property
45
51
def install_dir (self ) -> Path :
46
- install_dir = Path . home () / ".bash_completions"
52
+ install_dir = self . get_user_profile (). parent / ".bash_completions"
47
53
install_dir .mkdir (parents = True , exist_ok = True )
48
54
return install_dir
49
55
@@ -84,7 +90,7 @@ def install(self) -> Path:
84
90
assert self .prog_name
85
91
Path .home ().mkdir (parents = True , exist_ok = True )
86
92
script = self .install_dir / f"{ self .prog_name } .sh"
87
- bashrc = Path . home () / ".bashrc"
93
+ bashrc = self . get_user_profile ()
88
94
bashrc_source = bashrc .read_text () if bashrc .is_file () else ""
89
95
source_line = f"source { script } "
90
96
if source_line not in bashrc_source :
@@ -100,7 +106,7 @@ def uninstall(self):
100
106
if script .is_file ():
101
107
script .unlink ()
102
108
103
- bashrc = Path . home () / ".bashrc"
109
+ bashrc = self . get_user_profile ()
104
110
if bashrc .is_file ():
105
111
bashrc_source = bashrc .read_text ()
106
112
bashrc .write_text (bashrc_source .replace (f"source { script } \n " , "" ))
Original file line number Diff line number Diff line change
1
+ import os
1
2
from functools import cached_property
2
3
from pathlib import Path
3
4
@@ -36,9 +37,19 @@ class FishComplete(DjangoTyperShellCompleter):
36
37
Fish does not support ansi control codes.
37
38
"""
38
39
40
+ def get_user_profile (self ) -> Path :
41
+ """
42
+ Get the user's fish config file. It is located in the user's home directory by
43
+ default unless the ``XDG_CONFIG_HOME`` environment variable is set.
44
+ """
45
+ return (
46
+ Path (os .environ .get ("XDG_CONFIG_HOME" , Path .home () / ".config" ))
47
+ / "fish/config.fish"
48
+ )
49
+
39
50
@cached_property
40
51
def install_dir (self ) -> Path :
41
- install_dir = Path . home () / ".config/fish/ completions"
52
+ install_dir = self . get_user_profile (). parent / "completions"
42
53
install_dir .mkdir (parents = True , exist_ok = True )
43
54
return install_dir
44
55
Original file line number Diff line number Diff line change @@ -44,12 +44,19 @@ class ZshComplete(DjangoTyperShellCompleter):
44
44
by default.
45
45
"""
46
46
47
+ def get_user_profile (self ) -> Path :
48
+ """
49
+ Get the user's .zshrc file. It is located in the user's home directory by
50
+ default unless the ``ZDOTDIR`` environment variable is set.
51
+ """
52
+ return Path (os .environ .get ("ZDOTDIR" , Path .home ())) / ".zshrc"
53
+
47
54
@cached_property
48
55
def install_dir (self ) -> Path :
49
56
"""
50
57
The directory where completer scripts will be installed.
51
58
"""
52
- install_dir = Path . home () / ".zfunc"
59
+ install_dir = self . get_user_profile (). parent / ".zfunc"
53
60
install_dir .mkdir (parents = True , exist_ok = True )
54
61
return install_dir
55
62
@@ -60,7 +67,7 @@ def format_completion(self, item: CompletionItem) -> str:
60
67
def install (self ) -> Path :
61
68
assert self .prog_name
62
69
Path .home ().mkdir (parents = True , exist_ok = True )
63
- zshrc = Path . home () / ".zshrc"
70
+ zshrc = self . get_user_profile ()
64
71
zshrc_source = ""
65
72
if zshrc .is_file ():
66
73
zshrc_source = zshrc .read_text ()
@@ -94,7 +101,7 @@ def uninstall(self):
94
101
if script .is_file ():
95
102
script .unlink ()
96
103
97
- zshrc = Path . home () / ".zshrc"
104
+ zshrc = self . get_user_profile ()
98
105
if zshrc .is_file ():
99
106
zshrc_source = zshrc .read_text ()
100
107
zshrc .write_text (
You can’t perform that action at this time.
0 commit comments