twd-m4sc0 1.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tests/__init__.py +0 -0
- tests/test_twd.py +20 -0
- twd/__init__.py +0 -0
- twd/__main__.py +4 -0
- twd/twd.py +92 -0
- twd_m4sc0-1.1.0.dist-info/LICENSE +21 -0
- twd_m4sc0-1.1.0.dist-info/METADATA +13 -0
- twd_m4sc0-1.1.0.dist-info/RECORD +11 -0
- twd_m4sc0-1.1.0.dist-info/WHEEL +5 -0
- twd_m4sc0-1.1.0.dist-info/entry_points.txt +2 -0
- twd_m4sc0-1.1.0.dist-info/top_level.txt +2 -0
tests/__init__.py
ADDED
|
File without changes
|
tests/test_twd.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
import os
|
|
3
|
+
from twd import twd
|
|
4
|
+
|
|
5
|
+
class TestTWD(unittest.TestCase):
|
|
6
|
+
def test_save_directory(self):
|
|
7
|
+
twd.save_directory()
|
|
8
|
+
self.assertEqual(twd.TWD, os.getcwd())
|
|
9
|
+
|
|
10
|
+
def test_save_specified_directory(self):
|
|
11
|
+
path = "/tmp"
|
|
12
|
+
twd.save_directory(path)
|
|
13
|
+
self.assertEqual(twd.TWD, path)
|
|
14
|
+
|
|
15
|
+
def test_show_directory(self):
|
|
16
|
+
twd.TWD = "/tmp"
|
|
17
|
+
self.assertEqual(twd.TWD, "/tmp")
|
|
18
|
+
|
|
19
|
+
if __name__ == "__main__":
|
|
20
|
+
unittest.main()
|
twd/__init__.py
ADDED
|
File without changes
|
twd/__main__.py
ADDED
twd/twd.py
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import argparse
|
|
3
|
+
import sys
|
|
4
|
+
from importlib.metadata import version, PackageNotFoundError
|
|
5
|
+
|
|
6
|
+
TWD_FILE = os.path.join(os.path.expanduser("~"), ".twd")
|
|
7
|
+
|
|
8
|
+
def get_absolute_path(path):
|
|
9
|
+
return os.path.abspath(path)
|
|
10
|
+
|
|
11
|
+
def save_directory(path=None):
|
|
12
|
+
if path is None:
|
|
13
|
+
path = os.getcwd()
|
|
14
|
+
else:
|
|
15
|
+
path = get_absolute_path(path)
|
|
16
|
+
|
|
17
|
+
with open(TWD_FILE, "w") as f:
|
|
18
|
+
f.write(path)
|
|
19
|
+
|
|
20
|
+
print(f"Saved TWD to {path}")
|
|
21
|
+
|
|
22
|
+
def load_directory():
|
|
23
|
+
if not os.path.exists(TWD_FILE):
|
|
24
|
+
return None
|
|
25
|
+
|
|
26
|
+
with open(TWD_FILE, "r") as f:
|
|
27
|
+
return f.read().strip()
|
|
28
|
+
|
|
29
|
+
def go_to_directory():
|
|
30
|
+
TWD = load_directory()
|
|
31
|
+
|
|
32
|
+
if TWD is None:
|
|
33
|
+
print("No TWD found")
|
|
34
|
+
return 1
|
|
35
|
+
else:
|
|
36
|
+
if os.path.exists(TWD):
|
|
37
|
+
print(f"cd {TWD}")
|
|
38
|
+
return 0
|
|
39
|
+
else:
|
|
40
|
+
print(f"Directory does not exist: {TWD}")
|
|
41
|
+
return 1
|
|
42
|
+
|
|
43
|
+
def show_directory():
|
|
44
|
+
TWD = load_directory()
|
|
45
|
+
|
|
46
|
+
if TWD is None:
|
|
47
|
+
print("No TWD set")
|
|
48
|
+
else:
|
|
49
|
+
print(f"Current TWD: {TWD}")
|
|
50
|
+
|
|
51
|
+
def get_package_version():
|
|
52
|
+
try:
|
|
53
|
+
return version("twd_m4sc0")
|
|
54
|
+
except PackageNotFoundError:
|
|
55
|
+
return "Unknown version"
|
|
56
|
+
|
|
57
|
+
def main():
|
|
58
|
+
parser = argparse.ArgumentParser(description="Temporarily save and navigate to working directories.")
|
|
59
|
+
|
|
60
|
+
parser.add_argument('-s', '--save', nargs='?', const='', help="Save the current or specified directory")
|
|
61
|
+
parser.add_argument('-g', '--go', action='store_true', help="Go to the saved directory")
|
|
62
|
+
parser.add_argument('-l', '--list', action='store_true', help="Show saved TWD")
|
|
63
|
+
parser.add_argument('--shell', action='store_true', help="Output shell function for integration")
|
|
64
|
+
parser.add_argument('-v', '--version', action='version', version=f'TWD Version: {get_package_version()}', help='Show the current version of TWD installed')
|
|
65
|
+
|
|
66
|
+
args = parser.parse_args()
|
|
67
|
+
|
|
68
|
+
if args.shell:
|
|
69
|
+
print('''
|
|
70
|
+
function twd() {
|
|
71
|
+
output=$(python3 -m twd "$@")
|
|
72
|
+
if [[ "$1" == "-g" ]]; then
|
|
73
|
+
eval "$output"
|
|
74
|
+
else {
|
|
75
|
+
echo "$output"
|
|
76
|
+
fi
|
|
77
|
+
}
|
|
78
|
+
''')
|
|
79
|
+
return 0
|
|
80
|
+
|
|
81
|
+
if args.save is not None:
|
|
82
|
+
save_directory(args.save if args.save else None)
|
|
83
|
+
elif args.go:
|
|
84
|
+
return go_to_directory()
|
|
85
|
+
elif args.list:
|
|
86
|
+
show_directory()
|
|
87
|
+
else:
|
|
88
|
+
parser.print_help()
|
|
89
|
+
return 1
|
|
90
|
+
|
|
91
|
+
if __name__ == "__main__":
|
|
92
|
+
sys.exit(main())
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Masco
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: twd_m4sc0
|
|
3
|
+
Version: 1.1.0
|
|
4
|
+
Summary: A tool to temporarily save and go to a working directory
|
|
5
|
+
Home-page: https://github.com/m4sc0/twd
|
|
6
|
+
Author: m4sc0
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.6
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
tests/test_twd.py,sha256=XrxOo99oqida_7qZ48pA6BCazZekDmG5syw9NvjZWDU,484
|
|
3
|
+
twd/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
twd/__main__.py,sha256=gM_Py51pQFH3CXdDIuPzBW6eNlFH1UHeRAmgAPWQyik,61
|
|
5
|
+
twd/twd.py,sha256=5Xx8uot7-blhjxhJi9VvByrkg5P19Pwj_099yoQzJRM,2461
|
|
6
|
+
twd_m4sc0-1.1.0.dist-info/LICENSE,sha256=eQSDjcD_fvOwfjmrzxKJhtZsSI39seMawuvsgeD_dfw,1062
|
|
7
|
+
twd_m4sc0-1.1.0.dist-info/METADATA,sha256=IQiREj5PxX8J4MQd8UNWRP6QGn3ZRJNYqsRk2IAykLA,405
|
|
8
|
+
twd_m4sc0-1.1.0.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
|
|
9
|
+
twd_m4sc0-1.1.0.dist-info/entry_points.txt,sha256=QfYDHHjipkVN4oalpACFmIeYHb7GQCJY4SC12bTsiQQ,37
|
|
10
|
+
twd_m4sc0-1.1.0.dist-info/top_level.txt,sha256=PXToru2Yr2Xh3F_F-pHXtuOQVp5x7KKCPFf94P_VI5U,10
|
|
11
|
+
twd_m4sc0-1.1.0.dist-info/RECORD,,
|