twd-m4sc0 1.1.0__py3-none-any.whl → 1.2.1__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.
twd/twd.py CHANGED
@@ -8,7 +8,23 @@ TWD_FILE = os.path.join(os.path.expanduser("~"), ".twd")
8
8
  def get_absolute_path(path):
9
9
  return os.path.abspath(path)
10
10
 
11
- def save_directory(path=None):
11
+ def output_handler(message=None, path=None, output=True, simple_output=False):
12
+ """
13
+ Handles all output based on the flags --no-output and --simple-output.
14
+ - message: Regular output string
15
+ - path: Path to be printed (in simple output mode)
16
+ - output: Whether output is enabled
17
+ - simple_output: Whether only essential output should be shown
18
+ """
19
+ if not output:
20
+ return
21
+
22
+ if simple_output and path:
23
+ print(path)
24
+ elif not simple_output and message:
25
+ print(message)
26
+
27
+ def save_directory(path=None, output=True, simple_output=False):
12
28
  if path is None:
13
29
  path = os.getcwd()
14
30
  else:
@@ -17,36 +33,36 @@ def save_directory(path=None):
17
33
  with open(TWD_FILE, "w") as f:
18
34
  f.write(path)
19
35
 
20
- print(f"Saved TWD to {path}")
36
+ output_handler(f"Saved TWD to {path}", path, output, simple_output)
21
37
 
22
38
  def load_directory():
23
39
  if not os.path.exists(TWD_FILE):
24
40
  return None
25
-
41
+
26
42
  with open(TWD_FILE, "r") as f:
27
43
  return f.read().strip()
28
44
 
29
- def go_to_directory():
45
+ def go_to_directory(output=True, simple_output=False):
30
46
  TWD = load_directory()
31
-
47
+
32
48
  if TWD is None:
33
- print("No TWD found")
49
+ output_handler("No TWD found", None, output, simple_output)
34
50
  return 1
35
51
  else:
36
52
  if os.path.exists(TWD):
37
- print(f"cd {TWD}")
53
+ output_handler(f"cd {TWD}", TWD, output, simple_output)
38
54
  return 0
39
55
  else:
40
- print(f"Directory does not exist: {TWD}")
56
+ output_handler(f"Directory does not exist: {TWD}", None, output, simple_output)
41
57
  return 1
42
58
 
43
- def show_directory():
59
+ def show_directory(output=True, simple_output=False):
44
60
  TWD = load_directory()
45
-
61
+
46
62
  if TWD is None:
47
- print("No TWD set")
63
+ output_handler("No TWD set", None, output, simple_output)
48
64
  else:
49
- print(f"Current TWD: {TWD}")
65
+ output_handler(f"Current TWD: {TWD}", TWD, output, simple_output)
50
66
 
51
67
  def get_package_version():
52
68
  try:
@@ -56,22 +72,27 @@ def get_package_version():
56
72
 
57
73
  def main():
58
74
  parser = argparse.ArgumentParser(description="Temporarily save and navigate to working directories.")
59
-
75
+
60
76
  parser.add_argument('-s', '--save', nargs='?', const='', help="Save the current or specified directory")
61
77
  parser.add_argument('-g', '--go', action='store_true', help="Go to the saved directory")
62
78
  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
79
  parser.add_argument('-v', '--version', action='version', version=f'TWD Version: {get_package_version()}', help='Show the current version of TWD installed')
80
+ parser.add_argument('--shell', action='store_true', help="Output shell function for integration")
81
+ parser.add_argument('--simple-output', action='store_true', help="Only print essential output (new directory, absolute path, etc.)")
82
+ parser.add_argument('--no-output', action='store_true', help="Prevents the console from sending output")
65
83
 
66
84
  args = parser.parse_args()
67
85
 
86
+ output = not args.no_output
87
+ simple_output = args.simple_output
88
+
68
89
  if args.shell:
69
90
  print('''
70
91
  function twd() {
71
92
  output=$(python3 -m twd "$@")
72
93
  if [[ "$1" == "-g" ]]; then
73
94
  eval "$output"
74
- else {
95
+ else
75
96
  echo "$output"
76
97
  fi
77
98
  }
@@ -79,11 +100,11 @@ def main():
79
100
  return 0
80
101
 
81
102
  if args.save is not None:
82
- save_directory(args.save if args.save else None)
103
+ save_directory(args.save if args.save else None, output, simple_output)
83
104
  elif args.go:
84
- return go_to_directory()
105
+ return go_to_directory(output, simple_output)
85
106
  elif args.list:
86
- show_directory()
107
+ show_directory(output, simple_output)
87
108
  else:
88
109
  parser.print_help()
89
110
  return 1
@@ -0,0 +1,122 @@
1
+ Metadata-Version: 2.1
2
+ Name: twd_m4sc0
3
+ Version: 1.2.1
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
+
14
+ # twd-m4sc0
15
+
16
+ `twd-m4sc0` is a command-line tool that allows you to temporarily save a working directory and easily navigate back to it. It's designed for developers and all users who frequently need to switch between directories in the terminal.
17
+
18
+ ## Features
19
+
20
+ - Save the current working directory.
21
+ - Go back to the saved directory.
22
+ - List the saved directory.
23
+ - Integrates with your shell for seamless directory management.
24
+
25
+ ## Installation
26
+
27
+ ### Installation using `pip`:
28
+
29
+ 1. Install the package from the `pypi` repository:
30
+
31
+ ```bash
32
+ pip install twd-m4sc0
33
+ ```
34
+
35
+ 2. Add the following line to your `.bashrc` or `.zshrc` to set up the shell function:
36
+
37
+ ```bash
38
+ eval $(twd --shell)
39
+ ```
40
+
41
+ 3. Exit and reopen the terminal or reload using:
42
+
43
+ ```bash
44
+ source ~/.bashrc
45
+ # or
46
+ source ~/.zshrc
47
+ ```
48
+
49
+ ## Usage
50
+
51
+ - Save a directory
52
+
53
+ ```bash
54
+ twd -s [path]
55
+ ```
56
+
57
+ - Go to the saved directory
58
+
59
+ ```bash
60
+ twd -g
61
+ ```
62
+
63
+ - List the saved directory
64
+
65
+ ```bash
66
+ twd -l
67
+ ```
68
+
69
+ ### Optional Parameters
70
+
71
+ #### Simple Output
72
+
73
+ Simpler output is meant to be for script or grep usage
74
+
75
+ - Example with simple-output
76
+
77
+ ```bash
78
+ user:~/.config $ twd -s --simple-output
79
+ /home/user/.config
80
+ ```
81
+
82
+ - Example without simple-output
83
+
84
+ ```bash
85
+ user:~/.config $ twd -s
86
+ Saved TWD to /home/user/.config
87
+ ```
88
+
89
+ #### No Output
90
+
91
+ No output is meant for just no output (impressive ik)
92
+
93
+ - Example with no-output
94
+
95
+ ```bash
96
+ user:~/.config $ twd -s --no-output
97
+ # no output
98
+ ```
99
+
100
+ - Example without no-output
101
+
102
+ ```bash
103
+ user:~/.config $ twd -s
104
+ Saved TWD to /home/user/.config
105
+ ```
106
+
107
+ # Contribution
108
+
109
+ To set up a dev environment:
110
+
111
+ 1. Clone the repo:
112
+
113
+ ```bash
114
+ git clone https://github.com/m4sc0/twd
115
+ cd twd
116
+ ```
117
+
118
+ 2. Install the package in editable mode using `pip`:
119
+
120
+ ```bash
121
+ pip install -e .
122
+ ```
@@ -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=iFJhVhToU2Y7AJLSi6V57xsIvZUzRK1odRBpbrbM-Rk,3669
6
+ twd_m4sc0-1.2.1.dist-info/LICENSE,sha256=eQSDjcD_fvOwfjmrzxKJhtZsSI39seMawuvsgeD_dfw,1062
7
+ twd_m4sc0-1.2.1.dist-info/METADATA,sha256=ian4S9D3iTTXvvZnbTGoY2mqlgrgpZjUaXR4BMIMH6Y,2109
8
+ twd_m4sc0-1.2.1.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
9
+ twd_m4sc0-1.2.1.dist-info/entry_points.txt,sha256=QfYDHHjipkVN4oalpACFmIeYHb7GQCJY4SC12bTsiQQ,37
10
+ twd_m4sc0-1.2.1.dist-info/top_level.txt,sha256=PXToru2Yr2Xh3F_F-pHXtuOQVp5x7KKCPFf94P_VI5U,10
11
+ twd_m4sc0-1.2.1.dist-info/RECORD,,
@@ -1,13 +0,0 @@
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
-
@@ -1,11 +0,0 @@
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,,