Skip to content

Commit

Permalink
/home/jsd/Documents/personal command added
Browse files Browse the repository at this point in the history
  • Loading branch information
jasursadikov committed Nov 7, 2024
1 parent 0a17f4b commit 3499df6
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 25 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ paru -S mud-git
1. Run `mud config` to start interactive wizard which help you to set the preferable settings. Check [settings](#settings) section for more. At the end, `.mudsettings` file will appear at your home directory that you can alter in the future.
2. Locate to your preferable directory with repositories.
3. Run `mud init` command to create `.mudconfig` file. This file is important to keep references to repositories. All repositories in current dictionary would be included to `.mudconfig`.
4. Optional: Run [`mud --set-global`](#global-mudconfig) to make current configuration default and reachable from any directory.
4. Optional: Run [`mud set-global`](#commands) to make current configuration default and reachable from any directory.

All entries are stored in `.mudconfig` in TSV format. After making your first entry, you can open `.mudconfig` in a text editor and modify it according to your needs.

### Global .mudconfig
- `mud --set-global` - sets current `.mudconfig` as a global configuration, so it would be used as a fallback configuration to run from any directory.

## Using

### Commands
`mud <FILTER> <COMMAND>` will execute bash command across all repositories. To filter repositories check [arguments](#arguments) section.

- `mud set-global` - sets current `.mudconfig` as a global configuration, so it would be used as a fallback configuration to run from any directory.
- `mud get-config` - prints closest `.mudconfig` location.

`mud <FILTER> <COMMAND>` will execute bash command across all repositories. To filter repositories check [arguments](#arguments) section.
- `mud info`/`mud i` - displays branch divergence and working directory changes.
- `mud status`/`mud st` - displays working directory changes.
- `mud log`/`mud l` - displays latest commit message, it's time and it's author.
Expand All @@ -59,8 +59,11 @@ All entries are stored in `.mudconfig` in TSV format. After making your first en
Example:

```bash
mud -b=master -d git pull
# Filters out all repos with master branch and diverged branches and then runs pull command.
mud -b=master -d git pull

# Fetches all repositories that are not on master branch and have "personal" label but excluding ones with "work" label
mud -nb=master -l=personal -nl=work git fetch
```

## Settings
Expand Down
27 changes: 21 additions & 6 deletions src/mud/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,19 @@ def __init__(self):

@staticmethod
def _create_parser() -> ArgumentParser:
parser = argparse.ArgumentParser(description=f'{BOLD}mud{RESET} allows you to run commands in multiple repositories.')
parser = argparse.ArgumentParser(description=f'mud allows you to run commands in multiple repositories.')
subparsers = parser.add_subparsers(dest='command')

subparsers.add_parser(LOG[0], aliases=LOG[1:], help='Displays log of latest commit messages for all repositories in a table view.')
subparsers.add_parser(INFO[0], aliases=INFO[1:], help='Displays branch divergence and working directory changes')
subparsers.add_parser(INIT[0], aliases=INIT[1:], help=f'Initializes the {BOLD}.mudconfig{RESET} and adds all repositories in this directory to {BOLD}.mudconfig{RESET}.')
subparsers.add_parser(INIT[0], aliases=INIT[1:], help=f'Initializes the .mudconfig and adds all repositories in this directory to .mudconfig.')
subparsers.add_parser(TAGS[0], aliases=TAGS[1:], help='Displays git tags in repositories.')
subparsers.add_parser(LABELS[0], aliases=LABELS[1:], help='Displays mud labels across repositories.')
subparsers.add_parser(STATUS[0], aliases=STATUS[1:], help='Displays working directory changes.')
subparsers.add_parser(BRANCHES[0], aliases=BRANCHES[1:], help='Displays all branches in repositories.')
subparsers.add_parser(REMOTE_BRANCHES[0], aliases=REMOTE_BRANCHES[1:], help='Displays all remote branches in repositories.')
subparsers.add_parser(CONFIGURE[0], aliases=CONFIGURE[1:], help='Runs the interactive configuration wizard.')
subparsers.add_parser(GET_CONFIG[0], aliases=GET_CONFIG[1:], help='Prints current .mudconfig path.')

add_parser = subparsers.add_parser(ADD[0], aliases=ADD[1:], help='Adds repository or labels an existing repository.')
add_parser.add_argument('label', help='The label to add (optional).', nargs='?', default='', type=str)
Expand All @@ -53,7 +54,7 @@ def _create_parser() -> ArgumentParser:
parser.add_argument(*MODIFIED_ATTR, action='store_true', help='Filters modified repositories.')
parser.add_argument(*DIVERGED_ATTR, action='store_true', help='Filters repositories with diverged branches.')
parser.add_argument(*ASYNC_ATTR, action='store_true', help='Switches asynchronous run feature.')
parser.add_argument(SET_GLOBAL[0], help=f'Sets {BOLD}.mudconfig{RESET} in the current repository as your fallback {BOLD}.mudconfig{RESET}.', action='store_true')
parser.add_argument(SET_GLOBAL[0], help=f'Sets .mudconfig in the current repository as your fallback .mudconfig.', action='store_true')
parser.add_argument('catch_all', help='Type any commands to execute among repositories.', nargs='*')
return parser

Expand All @@ -66,11 +67,19 @@ def run(self) -> None:
return
# Sets global repository in .mudsettings
if sys.argv[1] in SET_GLOBAL:
config_path = os.path.join(os.getcwd(), utils.CONFIG_FILE_NAME)
if len(sys.argv) > 2:
config_path = sys.argv[2]
if not os.path.isabs(config_path):
config_path = os.path.abspath(config_path)
else:
config_path = os.path.join(os.getcwd(), utils.CONFIG_FILE_NAME)

if os.path.exists(config_path):
utils.settings.config.set('mud', 'config_path', config_path)
utils.settings.save()
print(f'Current {BOLD}.mudconfig{RESET} set as a global configuration.')
print(f'{config_path} set as a global.')
else:
utils.print_error(f'File {config_path} not found')
return
# Runs configuration wizard
elif sys.argv[1] in CONFIGURE:
Expand All @@ -85,7 +94,13 @@ def run(self) -> None:
self.init(self.parser.parse_args())
return

self.config.find()
config_path = self.config.find()

# Prints current config path
if sys.argv[1] in GET_CONFIG:
print(config_path)
return

self._filter_with_arguments()

self.cmd_runner = Runner(self.config)
Expand Down
5 changes: 3 additions & 2 deletions src/mud/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
REMOTE_BRANCHES = ['remote-branch', 'remote-branches', 'rbr']
HELP = ['help', '--help', '-h']
CONFIGURE = ['configure', 'config']
SET_GLOBAL = ['--set-global']
GET_CONFIG = ['get-config']
SET_GLOBAL = ['set-global']

COMMANDS = [ADD, REMOVE, LOG, INFO, INIT, TAGS, LABELS, STATUS, BRANCHES, REMOTE_BRANCHES, HELP, CONFIGURE, SET_GLOBAL]
COMMANDS = [ADD, REMOVE, LOG, INFO, INIT, TAGS, LABELS, STATUS, BRANCHES, REMOTE_BRANCHES, HELP, CONFIGURE, SET_GLOBAL, GET_CONFIG]

# Filters
ASYNC_ATTR = '-a', '--async'
Expand Down
16 changes: 5 additions & 11 deletions src/mud/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,24 @@ def _filter_labels(label: str):
formatted_labels = ','.join(valid_labels) if valid_labels else ''
writer.writerow([path, formatted_labels])

def find(self) -> None:
if os.path.exists(utils.CONFIG_FILE_NAME):
self.load(utils.CONFIG_FILE_NAME)
return

def find(self) -> str:
directory = os.getcwd()
current_path = directory
while os.path.dirname(current_path) != current_path:
os.chdir(current_path)
if os.path.exists(utils.CONFIG_FILE_NAME):
self.load(utils.CONFIG_FILE_NAME)
return utils.CONFIG_FILE_NAME
return current_path
current_path = os.path.dirname(current_path)

if utils.settings.mud_settings['config_path'] != '' and os.path.exists(
utils.settings.mud_settings['config_path']):
if utils.settings.mud_settings['config_path'] != '' and os.path.exists(utils.settings.mud_settings['config_path']):
directory = os.path.dirname(utils.settings.mud_settings['config_path'])
os.chdir(directory)
os.environ['PWD'] = directory
self.load(utils.CONFIG_FILE_NAME)
return
return current_path

utils.print_error(f'{BOLD}{utils.CONFIG_FILE_NAME}{RESET} was not found. Type `mud init` to create configuration file.', 11, exit=True)
return
utils.print_error(f'{BOLD}{utils.CONFIG_FILE_NAME}{RESET} was not found. Run \'mud init\' to create a configuration file.', 11, exit=True)

def load(self, file_path: str) -> None:
self.data = {}
Expand Down

0 comments on commit 3499df6

Please sign in to comment.