Skip to content

Commit

Permalink
Added gnu_coreutils.pwd()
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew15-5 committed Jan 21, 2022
1 parent b6b88fc commit ad22efa
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 9 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ python3 -m pip install niceshell

```bash
cd /tmp/
version=1.2.0 # Choose desired version
version=1.3.0 # Choose desired version
wget -c "https://github.com/Andrew15-5/niceshell/releases/download/v${version}/niceshell-${version}-py3-none-any.whl"
python3 -m pip -U --user install niceshell-${version}-py3-none-any.whl
```
Expand Down Expand Up @@ -89,10 +89,12 @@ provides for better understanding of what you are looking for.
* ln()
* ls()
* mv()
* pwd()
* rm()

## TODO list

* [x] Add pwd
* [x] Add functions to get dirs and files from path
* [x] Add ability to install module via pip
* [x] Add ability to get command's output and pipe it to another command
Expand All @@ -102,4 +104,3 @@ provides for better understanding of what you are looking for.
* [x] Add mv
* [x] Add rm
* [x] Add cp
* [x] Add shell() function for chain to start from small 's'
9 changes: 5 additions & 4 deletions niceshell/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
list_dirs,
list_files
)
from .gnu_coreutils import cd, cp, ln, ls, mv, rm
from .gnu_coreutils import cd, cp, ln, ls, mv, pwd, rm

__all__ = ["cd", "cp", "expose_tilde", "force_sudo_password_promt",
"get_root_privileges", "get_root_privileges_or_exit", "GID",
"GROUP", "has_root_privileges", "HOME", "list_dirs", "list_files",
"ln", "ls", "mv", "normalize_short_and_long_args", "quotes_wrapper",
"rm", "shell", "Shell", "ShortArgsOption", "UID", "USER"]
"ln", "ls", "mv", "normalize_short_and_long_args", "pwd",
"quotes_wrapper", "rm", "shell", "Shell", "ShortArgsOption", "UID",
"USER"]
__author__ = "Andrew Voynov"
__version__ = "1.2.0"
__version__ = "1.3.0"

GID = Shell("id -g").output()[:-1]
GROUP = Shell("id -gn").output()[:-1]
Expand Down
26 changes: 25 additions & 1 deletion niceshell/gnu_coreutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from .core import *

__all__ = ["cd", "cp", "ln", "ls", "mv", "rm"]
__all__ = ["cd", "cp", "ln", "ls", "mv", "pwd", "rm"]


def cd(path: str = '',
Expand Down Expand Up @@ -272,6 +272,30 @@ def mv(source_path: Union[str, Iterable[str]],
return Shell(command)


def pwd(short_args: Union[str, Iterable[str]] = [],
long_args: Iterable[str] = []) -> Union[str, Shell]:
"""
Returns present/current working directory (str) if no parameters have been
passed, otherwise returns Shell object.
Parameters:
short_args (str | Iterable[str]): string or array of short arguments.
Prefix-dash is ignored. Default is [] (no short arguments).
long_args (Iterable[str]): array of long arguments. Prefix-dashes are
ignored. Default is [] (no long arguments).
Returns:
Union[str, Shell]: PWD string if called without parameters, otherwise
Shell object.
"""
args = normalize_short_and_long_args(
short_args, long_args, ShortArgsOption.APART)
process = Shell(f"pwd {args}".strip())
if short_args == [] and long_args == []:
return process.output()[:-1]
return process


def rm(path: Union[str, Iterable[str]],
batch=False,
sudo=False,
Expand Down
4 changes: 4 additions & 0 deletions niceshell/gnu_coreutils.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ def mv(source_path: Union[str, Iterable[str]],
test: bool = False) -> Union[Shell, str]: ...


def pwd(short_args: Union[str, Iterable[str]] = [],
long_args: Iterable[str] = []) -> Union[str, Shell]: ...


def rm(path: Union[str, Iterable[str]],
batch: bool = False,
sudo: bool = False,
Expand Down
7 changes: 7 additions & 0 deletions niceshell/tests/test_gnu_coreutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pytest

sys.path.extend([f"{sys.path[0]}/..", f"{sys.path[0]}/../.."])
from niceshell import core
from niceshell import gnu_coreutils


Expand Down Expand Up @@ -377,6 +378,12 @@ def mv(source_path: Union[str, Iterable[str]],
assert mv(['"/dir 1" dir2/*'], '~', short_args='i'
) == 'mv -i -- "/dir 1" dir2/* ~'

def test_pwd(self):
pwd = gnu_coreutils.pwd
# Asserts
assert type(pwd()) == str
assert type(pwd('L')) == core.Shell

def test_rm(self):
rm = gnu_coreutils.rm
# Errors
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

setuptools.setup(
name="niceshell",
version="1.2.0",
version="1.3.0",
author="Andrew Voynov",
author_email="[email protected]",
description="Integration of shell and basic GNU core unilities for better coding.",
long_description=long_description,
long_description_content_type="text/markdown",
license="MIT",
url="https://github.com/Andrew15-5/niceshell",
download_url="https://github.com/Andrew15-5/niceshell/releases/download/v1.2.0/niceshell-1.2.0-py3-none-any.whl",
download_url="https://github.com/Andrew15-5/niceshell/releases/download/v1.3.0/niceshell-1.3.0-py3-none-any.whl",
packages=["niceshell", "niceshell/tests"],
package_data={
"niceshell": ['*']
Expand Down

0 comments on commit ad22efa

Please sign in to comment.