Browse Source

implement echo, reorganize coreutils

resolves #21
adam j hartz 1 year ago
parent
commit
0d9180a1c5

+ 1
- 1
setup.py View File

@@ -145,7 +145,7 @@ def main():
145 145
                      'Topic :: System :: Shells',
146 146
                      'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)'],
147 147
         packages=['takoshell', 'takoshell.ply', 'takoshell.parsers',
148
-                  'takoshell.xoreutils', 'takoshell.completers'],
148
+                  'takoshell.coreutils', 'takoshell.completers'],
149 149
         package_dir={'takoshell': 'takoshell'},
150 150
         package_data={'takoshell': ['*.json', 'LICENSE']},
151 151
         cmdclass=cmdclass

+ 2
- 1
takoshell/aliases.py View File

@@ -36,7 +36,7 @@ from argparse import ArgumentParser
36 36
 
37 37
 from takoshell.dirstack import cd, pushd, popd, dirs
38 38
 from takoshell.jobs import jobs, fg, bg, clean_jobs, disown
39
-from takoshell.xoreutils import _which
39
+from takoshell.coreutils import _which, _echo
40 40
 from takoshell.completers._aliases import completer_alias
41 41
 
42 42
 
@@ -373,4 +373,5 @@ default_aliases = {
373 373
     'fgrep': ['fgrep', '--color=auto'],
374 374
     'ls': ['ls', '--color=auto', '-v'],
375 375
     'suppress_tako_welcome_message': suppress_welcome,
376
+    'echo': _echo.echo,
376 377
 }

+ 0
- 0
takoshell/coreutils/__init__.py View File


+ 58
- 0
takoshell/coreutils/_echo.py View File

@@ -0,0 +1,58 @@
1
+# This file is part of tako
2
+# Copyright (c) 2015-2017 Adam Hartz <hartz@mit.edu> and contributors
3
+#
4
+# This program is free software: you can redistribute it and/or modify it under
5
+# the terms of the GNU General Public License as published by the Free Software
6
+# Foundation, either version 3 of the License, or (at your option) any later
7
+# version.
8
+#
9
+# This program is distributed in the hope that it will be useful, but WITHOUT
10
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
+# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
12
+# details.
13
+#
14
+# You should have received a copy of the GNU General Public License along with
15
+# this program.  If not, see <http://www.gnu.org/licenses/>.
16
+"""Implements a simple echo command for tako."""
17
+
18
+def echo(args, stdin, stdout, stderr):
19
+    """A simple echo command."""
20
+    opts = _echo_parse_args(args)
21
+    if opts is None:
22
+        return
23
+    if opts['help']:
24
+        print(ECHO_HELP, file=stdout)
25
+        return 0
26
+    ender = opts['end']
27
+    args = map(str, args)
28
+    if opts['escapes']:
29
+        args = map(lambda x: x.encode().decode('unicode_escape'), args)
30
+    print(*args, end=ender, file=stdout)
31
+
32
+
33
+def _echo_parse_args(args):
34
+    out = {'escapes': False, 'end': '\n', 'help': False}
35
+    if '-e' in args:
36
+        args.remove('-e')
37
+        out['escapes'] = True
38
+    if '-E' in args:
39
+        args.remove('-E')
40
+        out['escapes'] = False
41
+    if '-n' in args:
42
+        args.remove('-n')
43
+        out['end'] = ''
44
+    if '-h' in args or '--help' in args:
45
+        out['help'] = True
46
+    return out
47
+
48
+
49
+ECHO_HELP = """Usage: echo [OPTIONS]... [STRING]...
50
+Echo the STRING(s) to standard output.
51
+
52
+  -n             do not include the trailing newline
53
+  -e             enable interpretation of backslash escapes
54
+  -E             disable interpretation of backslash escapes (default)
55
+  -h  --help     display this message and exit
56
+
57
+This version of echo was written in Python for tako: https://takoshell.org
58
+Based on echo from GNU coreutils: http://www.gnu.org/software/coreutils/"""

takoshell/xoreutils/_which.py → takoshell/coreutils/_which.py View File


+ 0
- 21
takoshell/xoreutils/__init__.py View File

@@ -1,21 +0,0 @@
1
-# This file is part of tako
2
-# Copyright (c) 2015-2017 Adam Hartz <hartz@mit.edu> and contributors
3
-#
4
-# This program is free software: you can redistribute it and/or modify it under
5
-# the terms of the GNU General Public License as published by the Free Software
6
-# Foundation, either version 3 of the License, or (at your option) any later
7
-# version.
8
-#
9
-# This program is distributed in the hope that it will be useful, but WITHOUT
10
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
-# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
12
-# details.
13
-#
14
-# You should have received a copy of the GNU General Public License along with
15
-# this program.  If not, see <http://www.gnu.org/licenses/>.
16
-#
17
-#
18
-# tako is a fork of xonsh (http://xon.sh)
19
-# xonsh is Copyright (c) 2015-2016 the xonsh developers and is licensed under
20
-# the 2-Clause BSD license.
21
-

Loading…
Cancel
Save