1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
From dffcc1c5823bcce10b420467db41e42ec41f4702 Mon Sep 17 00:00:00 2001
From: Jeffery To <jeffery.to@gmail.com>
Date: Thu, 9 Nov 2023 17:48:50 +0800
Subject: [PATCH 1/2] Use Sh as base class for Bash and Zsh
---
userpath/shells.py | 41 ++++++++++++++++++++++++++---------------
1 file changed, 26 insertions(+), 15 deletions(-)
--- a/userpath/shells.py
+++ b/userpath/shells.py
@@ -12,24 +12,36 @@ class Shell(object):
class Sh(Shell):
- def config(self, location, front=True):
+ name = 'sh'
+
+ def _config_contents(self, location, front=True):
head, tail = (location, '$PATH') if front else ('$PATH', location)
new_path = '{}{}{}'.format(head, pathsep, tail)
+ return 'export PATH="{}"'.format(new_path)
+
+ def config(self, location, front=True):
+ contents = self._config_contents(location, front=front)
+ return {path.join(self.home, '.profile'): contents}
- return {path.join(self.home, '.profile'): 'PATH="{}"'.format(new_path)}
+ @classmethod
+ def _interactive_show_path_command(cls):
+ return [cls.name, '-i', '-c', 'echo $PATH']
+
+ @classmethod
+ def _interactive_login_show_path_command(cls):
+ return [cls.name, '-i', '-l', '-c', 'echo $PATH']
@classmethod
def show_path_commands(cls):
# TODO: Find out what file influences non-login shells. The issue may simply be our Docker setup.
- return [['sh', '-i', '-l', '-c', 'echo $PATH']]
+ return [cls._interactive_login_show_path_command()]
-class Bash(Shell):
- def config(self, location, front=True):
- head, tail = (location, '$PATH') if front else ('$PATH', location)
- new_path = '{}{}{}'.format(head, pathsep, tail)
- contents = 'export PATH="{}"'.format(new_path)
+class Bash(Sh):
+ name = 'bash'
+ def config(self, location, front=True):
+ contents = self._config_contents(location, front=front)
configs = {path.join(self.home, '.bashrc'): contents}
# https://github.com/ofek/userpath/issues/3#issuecomment-492491977
@@ -50,7 +62,7 @@ class Bash(Shell):
@classmethod
def show_path_commands(cls):
- return [['bash', '-i', '-c', 'echo $PATH'], ['bash', '-i', '-l', '-c', 'echo $PATH']]
+ return [cls._interactive_show_path_command(), cls._interactive_login_show_path_command()]
class Fish(Shell):
@@ -88,18 +100,17 @@ class Xonsh(Shell):
return [['xonsh', '-i', '-c', command], ['xonsh', '-i', '--login', '-c', command]]
-class Zsh(Shell):
- def config(self, location, front=True):
- head, tail = (location, '$PATH') if front else ('$PATH', location)
- new_path = '{}{}{}'.format(head, pathsep, tail)
- contents = 'export PATH="{}"'.format(new_path)
+class Zsh(Sh):
+ name = 'zsh'
+ def config(self, location, front=True):
+ contents = self._config_contents(location, front=front)
zdotdir = environ.get('ZDOTDIR', self.home)
return {path.join(zdotdir, '.zshrc'): contents, path.join(zdotdir, '.zprofile'): contents}
@classmethod
def show_path_commands(cls):
- return [['zsh', '-i', '-c', 'echo $PATH'], ['zsh', '-i', '-l', '-c', 'echo $PATH']]
+ return [cls._interactive_show_path_command(), cls._interactive_login_show_path_command()]
SHELLS = {
|