From 88138f2e71bb2dabeef40ddd35340a4ddb30361c Mon Sep 17 00:00:00 2001 From: risson Date: Wed, 5 Dec 2018 19:27:28 +0100 Subject: [PATCH] Add support for multiple arguments. Solves #4 --- README.md | 30 ++++++++++++++++++++++++++++++ advance_touch.py | 35 ++++++++++++++++++----------------- 2 files changed, 48 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 43d4b1c..4610822 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,8 @@ ad [path file or folder] ``` +And it supports multiple arguments! + ## Example ```bash @@ -32,6 +34,34 @@ airport/ │ ├── captain.txt ``` +--- + +```bash +ad airport/ train-station/train.txt +``` + +``` +airport/ +├── plane/ +train-station/ +├── train.txt +``` + +--- + +```bash +# If your shell supports arguments expansion +ad airport/plane/{captain,passenger}.txt +``` + +``` +airport/ +├── plane/ +│ ├── captain.txt +│ ├── passenger.txt +``` + +--- ## Install diff --git a/advance_touch.py b/advance_touch.py index 43180d8..f6a8e2a 100755 --- a/advance_touch.py +++ b/advance_touch.py @@ -6,25 +6,26 @@ import os import click @click.command() -@click.argument('path') +@click.argument('paths', nargs=-1) @click.option('-cd/--change', is_flag=True, default=False, help='After creating the directories, change to the new deeper directory.') -def advance_touch(path, cd): - """ Make folder and files """ - # Make folders - new_dirs = '/'.join(path.split('/')[0:-1]) - if not os.path.exists(new_dirs) and new_dirs != '': - os.makedirs(new_dirs) - # Change directory - if cd: - cd_path = os.path.join(os.getcwd(), new_dirs) + '/' - os.chdir(cd_path) +def advance_touch(paths, cd): + """ Make folders and files """ + for path in paths: + # Make folders + new_dirs = '/'.join(path.split('/')[0:-1]) + if not os.path.exists(new_dirs) and new_dirs != '': + os.makedirs(new_dirs) + # Change directory + if cd: + cd_path = os.path.join(os.getcwd(), new_dirs) + '/' + os.chdir(cd_path) - # Make file - if not path.endswith('/') and not os.path.isfile(path): - try: - open(path, 'w+').close() - except IsADirectoryError: - pass + # Make file + if not path.endswith('/') and not os.path.isfile(path): + try: + open(path, 'w+').close() + except IsADirectoryError: + pass if __name__ == '__main__': advance_touch() -- 2.54.0