Commit 0d9180a1 authored by adam j hartz's avatar adam j hartz

implement echo, reorganize coreutils

resolves #21
parent 03efe4f2
......@@ -145,7 +145,7 @@ def main():
'Topic :: System :: Shells',
'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)'],
packages=['takoshell', 'takoshell.ply', 'takoshell.parsers',
'takoshell.xoreutils', 'takoshell.completers'],
'takoshell.coreutils', 'takoshell.completers'],
package_dir={'takoshell': 'takoshell'},
package_data={'takoshell': ['*.json', 'LICENSE']},
......@@ -36,7 +36,7 @@ from argparse import ArgumentParser
from takoshell.dirstack import cd, pushd, popd, dirs
from import jobs, fg, bg, clean_jobs, disown
from takoshell.xoreutils import _which
from takoshell.coreutils import _which, _echo
from takoshell.completers._aliases import completer_alias
......@@ -373,4 +373,5 @@ default_aliases = {
'fgrep': ['fgrep', '--color=auto'],
'ls': ['ls', '--color=auto', '-v'],
'suppress_tako_welcome_message': suppress_welcome,
'echo': _echo.echo,
......@@ -13,9 +13,46 @@
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <>.
# tako is a fork of xonsh (
# xonsh is Copyright (c) 2015-2016 the xonsh developers and is licensed under
# the 2-Clause BSD license.
"""Implements a simple echo command for tako."""
def echo(args, stdin, stdout, stderr):
"""A simple echo command."""
opts = _echo_parse_args(args)
if opts is None:
if opts['help']:
print(ECHO_HELP, file=stdout)
return 0
ender = opts['end']
args = map(str, args)
if opts['escapes']:
args = map(lambda x: x.encode().decode('unicode_escape'), args)
print(*args, end=ender, file=stdout)
def _echo_parse_args(args):
out = {'escapes': False, 'end': '\n', 'help': False}
if '-e' in args:
out['escapes'] = True
if '-E' in args:
out['escapes'] = False
if '-n' in args:
out['end'] = ''
if '-h' in args or '--help' in args:
out['help'] = True
return out
ECHO_HELP = """Usage: echo [OPTIONS]... [STRING]...
Echo the STRING(s) to standard output.
-n do not include the trailing newline
-e enable interpretation of backslash escapes
-E disable interpretation of backslash escapes (default)
-h --help display this message and exit
This version of echo was written in Python for tako:
Based on echo from GNU coreutils:"""
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment