twd-m4sc0 1.2.0__tar.gz → 1.2.1__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: twd_m4sc0
3
- Version: 1.2.0
3
+ Version: 1.2.1
4
4
  Summary: A tool to temporarily save and go to a working directory
5
5
  Home-page: https://github.com/m4sc0/twd
6
6
  Author: m4sc0
@@ -64,12 +64,13 @@ twd -g
64
64
 
65
65
  ```bash
66
66
  twd -l
67
+ ```
67
68
 
68
69
  ### Optional Parameters
69
70
 
70
71
  #### Simple Output
71
72
 
72
- Simpler output is meant to be for script usage
73
+ Simpler output is meant to be for script or grep usage
73
74
 
74
75
  - Example with simple-output
75
76
 
@@ -85,6 +86,24 @@ user:~/.config $ twd -s
85
86
  Saved TWD to /home/user/.config
86
87
  ```
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
+
88
107
  # Contribution
89
108
 
90
109
  To set up a dev environment:
@@ -51,12 +51,13 @@ twd -g
51
51
 
52
52
  ```bash
53
53
  twd -l
54
+ ```
54
55
 
55
56
  ### Optional Parameters
56
57
 
57
58
  #### Simple Output
58
59
 
59
- Simpler output is meant to be for script usage
60
+ Simpler output is meant to be for script or grep usage
60
61
 
61
62
  - Example with simple-output
62
63
 
@@ -72,6 +73,24 @@ user:~/.config $ twd -s
72
73
  Saved TWD to /home/user/.config
73
74
  ```
74
75
 
76
+ #### No Output
77
+
78
+ No output is meant for just no output (impressive ik)
79
+
80
+ - Example with no-output
81
+
82
+ ```bash
83
+ user:~/.config $ twd -s --no-output
84
+ # no output
85
+ ```
86
+
87
+ - Example without no-output
88
+
89
+ ```bash
90
+ user:~/.config $ twd -s
91
+ Saved TWD to /home/user/.config
92
+ ```
93
+
75
94
  # Contribution
76
95
 
77
96
  To set up a dev environment:
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="twd_m4sc0",
5
- version="1.2.0",
5
+ version="1.2.1",
6
6
  packages=find_packages(),
7
7
  entry_points={
8
8
  "console_scripts": [
@@ -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, output=None, simple_output=False):
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,48 +33,36 @@ def save_directory(path=None, output=None, simple_output=False):
17
33
  with open(TWD_FILE, "w") as f:
18
34
  f.write(path)
19
35
 
20
- if output and not simple_output:
21
- print(f"Saved TWD to {path}")
22
- elif output and simple_output:
23
- print(path)
36
+ output_handler(f"Saved TWD to {path}", path, output, simple_output)
24
37
 
25
38
  def load_directory():
26
39
  if not os.path.exists(TWD_FILE):
27
40
  return None
28
-
41
+
29
42
  with open(TWD_FILE, "r") as f:
30
43
  return f.read().strip()
31
44
 
32
- def go_to_directory(output, simple_output=False):
45
+ def go_to_directory(output=True, simple_output=False):
33
46
  TWD = load_directory()
34
-
47
+
35
48
  if TWD is None:
36
- if output and not simple_output:
37
- print("No TWD found")
49
+ output_handler("No TWD found", None, output, simple_output)
38
50
  return 1
39
51
  else:
40
52
  if os.path.exists(TWD):
41
- if output and simple_output:
42
- print(TWD)
43
- elif output and not simple_output:
44
- print(f"cd {TWD}")
53
+ output_handler(f"cd {TWD}", TWD, output, simple_output)
45
54
  return 0
46
55
  else:
47
- if output and not simple_output:
48
- print(f"Directory does not exist: {TWD}")
56
+ output_handler(f"Directory does not exist: {TWD}", None, output, simple_output)
49
57
  return 1
50
58
 
51
- def show_directory(output, simple_output=False):
59
+ def show_directory(output=True, simple_output=False):
52
60
  TWD = load_directory()
53
-
61
+
54
62
  if TWD is None:
55
- if output and not simple_output:
56
- print("No TWD set")
63
+ output_handler("No TWD set", None, output, simple_output)
57
64
  else:
58
- if output and simple_output:
59
- print(TWD)
60
- elif output and not simple_output:
61
- print(f"Current TWD: {TWD}")
65
+ output_handler(f"Current TWD: {TWD}", TWD, output, simple_output)
62
66
 
63
67
  def get_package_version():
64
68
  try:
@@ -68,12 +72,12 @@ def get_package_version():
68
72
 
69
73
  def main():
70
74
  parser = argparse.ArgumentParser(description="Temporarily save and navigate to working directories.")
71
-
75
+
72
76
  parser.add_argument('-s', '--save', nargs='?', const='', help="Save the current or specified directory")
73
77
  parser.add_argument('-g', '--go', action='store_true', help="Go to the saved directory")
74
78
  parser.add_argument('-l', '--list', action='store_true', help="Show saved TWD")
75
- parser.add_argument('--shell', action='store_true', help="Output shell function for integration")
76
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")
77
81
  parser.add_argument('--simple-output', action='store_true', help="Only print essential output (new directory, absolute path, etc.)")
78
82
  parser.add_argument('--no-output', action='store_true', help="Prevents the console from sending output")
79
83
 
@@ -83,14 +87,16 @@ def main():
83
87
  simple_output = args.simple_output
84
88
 
85
89
  if args.shell:
86
- print('''function twd() {
90
+ print('''
91
+ function twd() {
87
92
  output=$(python3 -m twd "$@")
88
93
  if [[ "$1" == "-g" ]]; then
89
94
  eval "$output"
90
- else {
95
+ else
91
96
  echo "$output"
92
97
  fi
93
- }''')
98
+ }
99
+ ''')
94
100
  return 0
95
101
 
96
102
  if args.save is not None:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: twd_m4sc0
3
- Version: 1.2.0
3
+ Version: 1.2.1
4
4
  Summary: A tool to temporarily save and go to a working directory
5
5
  Home-page: https://github.com/m4sc0/twd
6
6
  Author: m4sc0
@@ -64,12 +64,13 @@ twd -g
64
64
 
65
65
  ```bash
66
66
  twd -l
67
+ ```
67
68
 
68
69
  ### Optional Parameters
69
70
 
70
71
  #### Simple Output
71
72
 
72
- Simpler output is meant to be for script usage
73
+ Simpler output is meant to be for script or grep usage
73
74
 
74
75
  - Example with simple-output
75
76
 
@@ -85,6 +86,24 @@ user:~/.config $ twd -s
85
86
  Saved TWD to /home/user/.config
86
87
  ```
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
+
88
107
  # Contribution
89
108
 
90
109
  To set up a dev environment:
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes