Galaxie Shell 0.2.6 documentation


Navigation:   | Index   | Search   | Top   | Up   |
Table of Content: |

© Copyright 2020-2024, Galaxie Shell Team.

Top » Module code » glxshell.utilities.pwd

Source code for glxshell.utilities.pwd

# inspired by: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/pwd.html
import os
import sys
from glxshell.lib.path import normpath
from glxshell.lib.path import realpath
from glxshell.lib.argparse import ArgumentParser

parser_pwd = ArgumentParser(
    name="pwd - return working directory name",
    description="The pwd utility shall write to standard output an absolute pathname of the current working "
    "directory, which does not contain the filenames dot or dot-dot.",
)
parser_pwd.add_argument(
    "-L",
    dest="logical",
    action="store_true",
    default=False,
    help="Print the value of $PWD if it names the current working directory",
)
parser_pwd.add_argument(
    "-P",
    dest="physical",
    action="store_true",
    default=False,
    help="Print the physical directory, without any symbolic links",
)


[docs] def glxsh_pwd(logical=None, physical=None): """ The pwd utility shall write to standard output an absolute pathname of the current working directory, which does not contain the filenames dot or dot-dot. If both ``logical`` and ``physical`` are specified, the last one shall apply. If neither ``logical`` nor ``physical`` is specified, the pwd utility shall behave as if ``logical`` had been specified. :param logical: If the PWD environment variable contains an absolute pathname of the current directory and the pathname does not contain any components that are dot or dot-dot :type logical: bool :param physical: The pathname written to standard output shall not contain any components that refer to files of type symbolic link :type physical: bool """ if not logical and not physical: logical = True try: if logical: sys.stdout.write("%s\n" % normpath(os.getcwd())) else: sys.stdout.write("%s\n" % realpath(os.getcwd())) return 0 except (Exception, ArithmeticError) as error: # pragma: no cover sys.stderr.write("pwd: %s\n" % error) return 1

Top » Module code » glxshell.utilities.pwd

© Copyright 2020-2024, Galaxie Shell Team.
This page is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License (CC BY-NC-SA 4.0).
Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
See History and License for more information.

Last updated on None.
Created using Sphinx 8.0.2.