Skip to content

Commit

Permalink
removed :: and added param feature
Browse files Browse the repository at this point in the history
  • Loading branch information
RaghavGohil committed Sep 21, 2023
1 parent a18e339 commit 4d0c0dc
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 64 deletions.
40 changes: 19 additions & 21 deletions build/lib/cbuff/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ def exec_op()->None:
set_buffer()
try:
if sys.argv[1] == 'push' or sys.argv[1] == 'p':
push_command(sys.argv[3],sys.argv[2]) # push the alias and command in order

push_command(sys.argv[3],sys.argv[2]) # push the description, alias and command in order
elif sys.argv[1] == 'view' or sys.argv[1] == 'v':
view_commands()

Expand All @@ -52,52 +51,51 @@ def exec_op()->None:
The default storage dir is downloads.
The users will be able to:
- push one commands -> cbuff push | p <command> <alias>
- push multiple commands -> cbuff push | p "<command1>:<command2>" <alias>
- push one command -> cbuff push | p <command> <alias>
- push multiple commands -> cbuff push | p "<command1>&&<command2>" <alias>
- push a path when alias is prefixed by @ (open terminal) -> cbuff push | p <path> @<alias>
- view the commands with their unique alias key -> cbuff view | v
- run pushed commands with that alias key -> cbuff <alias>
- pass params when you run alias (command must contain {}) -> cbuff <alias> <param1> <param2> ...
- remove the pushed commands with the key -> cbuff remove | r <alias>
- open the buffer in notepad/vim for quick edit -> cbuff open | o
- reset the system -> cbuff reset | re
- get help -> cbuff help | h
- get help for cbuff -> cbuff help | h
Note that you can use "" while making an alias for storing commands having spaces.
* You can provide an alias for cbuff altogether. Instead of typing cbuff you can define something like 'cb' in your terminal.
* You can use "" while making an alias for storing commands having spaces.
* You can execute cbuff commands inside cbuff.
* You can combine cbuff commands like cbuff p "cbuff reset&&cbuff open" quick-edit
and run it like : cbuff quick-edit or cb quick-edit if defined as stated earlier.
''')
elif sys.argv[1] not in COMMANDS: # if input is an alias
execute_command(sys.argv[1])
param_list=sys.argv[2:]
execute_command(sys.argv[1],param_list)
except Exception as e:
print("Invalid use of cbuff. Use cbuff help for more information.")
print("\n",e)
#print("\n",e)

def set_buffer()->None:
with open(BUFFER_PATH , 'a') as buffer:
with open(BUFFER_PATH , 'a'):
pass

def execute_command(alias:str)->None:
def execute_command(alias:str,params:list=[])->None:
json_data = {}
c_list = []
with open(BUFFER_PATH , 'r') as buffer:
json_data = json.loads(get_data(buffer.read()))
keys = json_data.keys()
if alias in keys:
if alias[0] == '@': # is a path alias
if sys.platform.startswith('win'):
# On Windows, use the "start" command to open a new command prompt window
subprocess.Popen(['cmd', '/K', f'cd /D {json_data[alias]}'],shell=True,creationflags=subprocess.DETACHED_PROCESS)
subprocess.Popen(['cmd', '/K', f'cd /D {json_data[alias].format(*params)}'],shell=True,creationflags=subprocess.DETACHED_PROCESS)

elif sys.platform.startswith('linux') or sys.platform.startswith('darwin'):
# On Linux and macOS, use the terminal emulator to open a new terminal window
terminal = os.getenv('TERMINAL', 'x-terminal-emulator') # Use 'x-terminal-emulator' as the default
subprocess.Popen([terminal, '--working-directory', json_data[alias]],shell=True,creationflags=subprocess.DETACHED_PROCESS)
subprocess.Popen([terminal, '--working-directory', json_data[alias].format(*params)],shell=True,creationflags=subprocess.DETACHED_PROCESS)
else:
if '::' in json_data[alias]:
c_list = json_data[alias].split("::")
print(c_list)
for commands in c_list:
os.system(commands)
else:
os.system(json_data[alias])
os.system(json_data[alias].format(*params))
else:
exit_r('Alias not found. Define an alias using cbuff push.')

Expand All @@ -118,7 +116,7 @@ def open_buffer():
subprocess.run("vim "+BUFFER_PATH)

def reset_buffer():
with open(BUFFER_PATH , 'w') as buffer:
with open(BUFFER_PATH , 'w'):
pass

def remove_command(alias:str)->None:
Expand Down
6 changes: 3 additions & 3 deletions build/lib/cbuff/settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = 'cbuff'
version = '1.0.0'
description = 'A command buffer for windows command prompt.'
version = '1.0.1'
description = 'A command buffer for terminals.'
author = 'RaghavGohil'
author_email = 'raghavgohil2004@gmail.com'
project_url = 'https://github.com/RaghavGohil/cbuff'
Expand All @@ -16,7 +16,7 @@
exclude_packages = ('tests')
license = 'MIT LICENSE'
license_files = ('LICENSE.txt')
keywords = 'command buffer for windows command prompt '
keywords = 'command buffer terminal storage windows linux macos '
install_requires = ['readme_renderer >= 21.0']
include_package_data = True
python_requires='>=3.0'
34 changes: 25 additions & 9 deletions cbuff.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
Metadata-Version: 2.1
Name: cbuff
Version: 1.0.0
Summary: A command buffer for windows command prompt.
Version: 1.0.1
Summary: A command buffer for terminals.
Home-page: https://github.com/RaghavGohil/cbuff
Author: RaghavGohil
Author-email: raghavgohil2004@gmail.com
License: MIT LICENSE
Description: # cbuff - Command Buffer
Description: ![cbuff](https://github.com/RaghavGohil/cbuff/assets/71706645/4343a690-f4b4-402a-a83f-5849803cb642)

![version](https://img.shields.io/badge/version-1.0.1-blue)
![python](https://img.shields.io/badge/lang-python3-green)

# cbuff - Command Buffer

```cbuff``` (short for Command Buffer) is a versatile command-line tool that empowers users to efficiently store, manage, and execute frequently used commands and workflows. With its user-friendly interface, cbuff simplifies command-line tasks, improves productivity, and reduces the risk of errors.

cbuff can store long paths, commands, also multiple commands which can run sequentially.
- cbuff can store long paths, commands, also multiple commands which can run sequentially.

- cbuff can take parameters so you don't have to write a big command again.

- It is preferred to use an alias for cbuff. Something like 'cb'. Currently you have to define it manually.

## Key Features

Expand All @@ -36,19 +45,26 @@ Description: # cbuff - Command Buffer

How to use cbuff:

This program will help users to create a cmd prompt command dictionary.

The default storage dir is downloads.
The users will be able to:
- push one commands -> cbuff push | p <command> <alias>
- push multiple commands -> cbuff push | p "<command1>:<command2>" <alias>
- push one command -> cbuff push | p <command> <alias>
- push multiple commands -> cbuff push | p "<command1>&&<command2>" <alias>
- push a path when alias is prefixed by @ (open terminal) -> cbuff push | p <path> @<alias>
- view the commands with their unique alias key -> cbuff view | v
- run pushed commands with that alias key -> cbuff <alias>
- pass params when you run alias (command must contain {}) -> cbuff <alias> <param1> <param2> ...
- remove the pushed commands with the key -> cbuff remove | r <alias>
- open the buffer in notepad/vim for quick edit -> cbuff open | o
- reset the system -> cbuff reset | re
- get help -> cbuff help | h
- get help for cbuff -> cbuff help | h

Note that you can use "" while making an alias for storing commands having spaces.
* You can provide an alias for cbuff altogether. Instead of typing cbuff you can define something like 'cb' in your terminal.
* You can use "" while making an alias for storing commands having spaces.
* You can execute cbuff commands inside cbuff.
* You can combine cbuff commands like cbuff p "cbuff reset&&cbuff open" quick-edit
and run it like : cbuff quick-edit or cb quick-edit if defined as stated earlier.

## License

Expand All @@ -58,7 +74,7 @@ Description: # cbuff - Command Buffer

Contributions to `cbuff` are welcome! If you'd like to contribute or report issues, please visit the [cbuff GitHub repository](https://github.com/RaghavGohil/cbuff).

Keywords: command buffer for windows command prompt
Keywords: command buffer terminal storage windows linux macos
Platform: UNKNOWN
Classifier: Development Status :: 1 - Planning
Classifier: License :: OSI Approved :: MIT License
Expand Down
Binary file modified cbuff/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file modified cbuff/__pycache__/settings.cpython-39.pyc
Binary file not shown.
40 changes: 19 additions & 21 deletions cbuff/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ def exec_op()->None:
set_buffer()
try:
if sys.argv[1] == 'push' or sys.argv[1] == 'p':
push_command(sys.argv[3],sys.argv[2]) # push the alias and command in order

push_command(sys.argv[3],sys.argv[2]) # push the description, alias and command in order
elif sys.argv[1] == 'view' or sys.argv[1] == 'v':
view_commands()

Expand All @@ -52,52 +51,51 @@ def exec_op()->None:
The default storage dir is downloads.
The users will be able to:
- push one commands -> cbuff push | p <command> <alias>
- push multiple commands -> cbuff push | p "<command1>::<command2>" <alias>
- push one command -> cbuff push | p <command> <alias>
- push multiple commands -> cbuff push | p "<command1>&&<command2>" <alias>
- push a path when alias is prefixed by @ (open terminal) -> cbuff push | p <path> @<alias>
- view the commands with their unique alias key -> cbuff view | v
- run pushed commands with that alias key -> cbuff <alias>
- pass params when you run alias (command must contain {}) -> cbuff <alias> <param1> <param2> ...
- remove the pushed commands with the key -> cbuff remove | r <alias>
- open the buffer in notepad/vim for quick edit -> cbuff open | o
- reset the system -> cbuff reset | re
- get help -> cbuff help | h
- get help for cbuff -> cbuff help | h
Note that you can use "" while making an alias for storing commands having spaces.
* You can provide an alias for cbuff altogether. Instead of typing cbuff you can define something like 'cb' in your terminal.
* You can use "" while making an alias for storing commands having spaces.
* You can execute cbuff commands inside cbuff.
* You can combine cbuff commands like cbuff p "cbuff reset&&cbuff open" quick-edit
and run it like : cbuff quick-edit or cb quick-edit if defined as stated earlier.
''')
elif sys.argv[1] not in COMMANDS: # if input is an alias
execute_command(sys.argv[1])
param_list=sys.argv[2:]
execute_command(sys.argv[1],param_list)
except Exception as e:
print("Invalid use of cbuff. Use cbuff help for more information.")
print("\n",e)
#print("\n",e)

def set_buffer()->None:
with open(BUFFER_PATH , 'a') as buffer:
with open(BUFFER_PATH , 'a'):
pass

def execute_command(alias:str)->None:
def execute_command(alias:str,params:list=[])->None:
json_data = {}
c_list = []
with open(BUFFER_PATH , 'r') as buffer:
json_data = json.loads(get_data(buffer.read()))
keys = json_data.keys()
if alias in keys:
if alias[0] == '@': # is a path alias
if sys.platform.startswith('win'):
# On Windows, use the "start" command to open a new command prompt window
subprocess.Popen(['cmd', '/K', f'cd /D {json_data[alias]}'],shell=True,creationflags=subprocess.DETACHED_PROCESS)
subprocess.Popen(['cmd', '/K', f'cd /D {json_data[alias].format(*params)}'],shell=True,creationflags=subprocess.DETACHED_PROCESS)

elif sys.platform.startswith('linux') or sys.platform.startswith('darwin'):
# On Linux and macOS, use the terminal emulator to open a new terminal window
terminal = os.getenv('TERMINAL', 'x-terminal-emulator') # Use 'x-terminal-emulator' as the default
subprocess.Popen([terminal, '--working-directory', json_data[alias]],shell=True,creationflags=subprocess.DETACHED_PROCESS)
subprocess.Popen([terminal, '--working-directory', json_data[alias].format(*params)],shell=True,creationflags=subprocess.DETACHED_PROCESS)
else:
if '::' in json_data[alias]:
c_list = json_data[alias].split("::")
print(c_list)
for commands in c_list:
os.system(commands)
else:
os.system(json_data[alias])
os.system(json_data[alias].format(*params))
else:
exit_r('Alias not found. Define an alias using cbuff push.')

Expand All @@ -118,7 +116,7 @@ def open_buffer():
subprocess.run("vim "+BUFFER_PATH)

def reset_buffer():
with open(BUFFER_PATH , 'w') as buffer:
with open(BUFFER_PATH , 'w'):
pass

def remove_command(alias:str)->None:
Expand Down
6 changes: 3 additions & 3 deletions cbuff/settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = 'cbuff'
version = '1.0.0'
description = 'A command buffer for windows command prompt.'
version = '1.0.1'
description = 'A command buffer for terminals.'
author = 'RaghavGohil'
author_email = 'raghavgohil2004@gmail.com'
project_url = 'https://github.com/RaghavGohil/cbuff'
Expand All @@ -16,7 +16,7 @@
exclude_packages = ('tests')
license = 'MIT LICENSE'
license_files = ('LICENSE.txt')
keywords = 'command buffer for windows command prompt '
keywords = 'command buffer terminal storage windows linux macos '
install_requires = ['readme_renderer >= 21.0']
include_package_data = True
python_requires='>=3.0'
Binary file removed dist/cbuff-1.0.0-py3-none-any.whl
Binary file not shown.
Binary file removed dist/cbuff-1.0.0.tar.gz
Binary file not shown.
Binary file added dist/cbuff-1.0.1-py3-none-any.whl
Binary file not shown.
Binary file added dist/cbuff-1.0.1.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion install.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@echo installing python lib..

set file=cbuff-1.0.0-py3-none-any.whl
set file=cbuff-1.0.1-py3-none-any.whl

pip uninstall %file%
python setup.py sdist bdist_wheel
Expand Down
23 changes: 17 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
![cbuff](https://github.com/RaghavGohil/cbuff/assets/71706645/4343a690-f4b4-402a-a83f-5849803cb642)

![version](https://img.shields.io/badge/version-1.0.0-blue)
![version](https://img.shields.io/badge/version-1.0.1-blue)
![python](https://img.shields.io/badge/lang-python3-green)

# cbuff - Command Buffer

```cbuff``` (short for Command Buffer) is a versatile command-line tool that empowers users to efficiently store, manage, and execute frequently used commands and workflows. With its user-friendly interface, cbuff simplifies command-line tasks, improves productivity, and reduces the risk of errors.

cbuff can store long paths, commands, also multiple commands which can run sequentially.
- cbuff can store long paths, commands, also multiple commands which can run sequentially.

- cbuff can take parameters so you don't have to write a big command again.

- It is preferred to use an alias for cbuff. Something like 'cb'. Currently you have to define it manually.

## Key Features

Expand All @@ -33,19 +37,26 @@ Use ```pip install cbuff``` to install cbuffer.

How to use cbuff:

This program will help users to create a cmd prompt command dictionary.

The default storage dir is downloads.
The users will be able to:
- push one commands -> cbuff push | p <command> <alias>
- push multiple commands -> cbuff push | p "<command1>::<command2>" <alias>
- push one command -> cbuff push | p <command> <alias>
- push multiple commands -> cbuff push | p "<command1>&&<command2>" <alias>
- push a path when alias is prefixed by @ (open terminal) -> cbuff push | p <path> @<alias>
- view the commands with their unique alias key -> cbuff view | v
- run pushed commands with that alias key -> cbuff <alias>
- pass params when you run alias (command must contain {}) -> cbuff <alias> <param1> <param2> ...
- remove the pushed commands with the key -> cbuff remove | r <alias>
- open the buffer in notepad/vim for quick edit -> cbuff open | o
- reset the system -> cbuff reset | re
- get help -> cbuff help | h
- get help for cbuff -> cbuff help | h

Note that you can use "" while making an alias for storing commands having spaces.
* You can provide an alias for cbuff altogether. Instead of typing cbuff you can define something like 'cb' in your terminal.
* You can use "" while making an alias for storing commands having spaces.
* You can execute cbuff commands inside cbuff.
* You can combine cbuff commands like cbuff p "cbuff reset&&cbuff open" quick-edit
and run it like : cbuff quick-edit or cb quick-edit if defined as stated earlier.

## License

Expand Down

0 comments on commit 4d0c0dc

Please sign in to comment.