diff --git a/.oh-my-zsh/custom/plugins/taskbook/taskbook.plugin.zsh b/.oh-my-zsh/custom/plugins/taskbook/taskbook.plugin.zsh new file mode 100644 index 00000000..071e2bcf --- /dev/null +++ b/.oh-my-zsh/custom/plugins/taskbook/taskbook.plugin.zsh @@ -0,0 +1,14 @@ +# Taskbook command completion + +# Functio + +_taskbook_commands () { + if which tb &> /dev/null; then + array_of_lines=("${(@f)$(tb | grep -o '[0-9]\+\..*\|@\w*')}") + compadd -d array_of_lines -X 'Some completions' -- $(tb | grep -o '[0-9]\+\.\|@\w*' | grep -o '[0-9]\+\|@\w*') + fi +} + +# Completion setup +compdef _taskbook_commands tb + diff --git a/cli.js b/cli.js index 253e82f6..017ef7fb 100755 --- a/cli.js +++ b/cli.js @@ -60,6 +60,10 @@ const cli = meow(help, { type: 'boolean', alias: 'p' }, + swap: { + type: 'boolean', + alias: 'w' + }, find: { type: 'boolean', alias: 'f' diff --git a/index.js b/index.js index 52041e1e..cade93b4 100644 --- a/index.js +++ b/index.js @@ -39,6 +39,10 @@ const taskbookCLI = (input, flags) => { return taskbook.updatePriority(input); } + if (flags.swap) { + return taskbook.swapItems(input); + } + if (flags.copy) { return taskbook.copyToClipboard(input); } diff --git a/readme.md b/readme.md index fbbe5ed0..3991d58f 100644 --- a/readme.md +++ b/readme.md @@ -118,6 +118,7 @@ $ tb --help --priority, -p Update priority of task --restore, -r Restore items from archive --star, -s Star/unstar item + --swap, -w Swap items --task, -t Create task --timeline, -i Display timeline view --version, -v Display installed version @@ -138,6 +139,7 @@ $ tb --help $ tb --priority @3 2 $ tb --restore 4 $ tb --star 2 + $ tb --swap 2 1 $ tb --task @coding @reviews Review PR #42 $ tb --task @coding Improve documentation $ tb --task Make some buttercream @@ -254,6 +256,14 @@ To mark one or more items as favorite, use the `--star`/`-s` option followed by $ tb -s 1 2 3 ``` +### Swap items + +To swap items positions, use the `--swap`/`-s` option followed by the ids of the 2 items which will be swapped. + +``` +$ tb -w 2 1 +``` + ### Copy Item Description To copy to your system's clipboard the description of one or more items, use the `--copy`/`-y` option followed by the ids of the target items. Note that the option will also include the newline character as a separator to each pair of adjacent copied descriptions, thus resulting in a clear and readable stack of sentences on paste. diff --git a/src/help.js b/src/help.js index a9b4f344..5ae6f5d4 100644 --- a/src/help.js +++ b/src/help.js @@ -21,6 +21,7 @@ module.exports = ` --priority, -p Update priority of task --restore, -r Restore items from archive --star, -s Star/unstar item + --swap, -w Swap items --task, -t Create task --timeline, -i Display timeline view --version, -v Display installed version @@ -41,6 +42,7 @@ module.exports = ` $ tb --priority @3 2 $ tb --restore 4 $ tb --star 2 + $ tb --swap 2 1 $ tb --task @coding @reviews Review PR #42 $ tb --task @coding Improve documentation $ tb --task Make some buttercream diff --git a/src/render.js b/src/render.js index 75db161b..8adc80b4 100644 --- a/src/render.js +++ b/src/render.js @@ -212,6 +212,12 @@ class Render { error({prefix, message}); } + notEnoughIDsNumber() { + const prefix = '\n'; + const message = 'Not enough ids were given as input'; + error({prefix, message}); + } + invalidPriority() { const prefix = '\n'; const message = 'Priority can only be 1, 2 or 3'; @@ -278,6 +284,16 @@ class Render { success({prefix, message, suffix}); } + swapSuccess(ids) { + if (ids.length != 2) { + return; + } + + const [prefix, suffix] = ['\n', grey(ids.join(', '))]; + const message = `Swapped items:`; + success({prefix, message, suffix}); + } + missingBoards() { const prefix = '\n'; const message = 'No boards were given as input'; diff --git a/src/taskbook.js b/src/taskbook.js index d6ff4cf1..97ac2163 100644 --- a/src/taskbook.js +++ b/src/taskbook.js @@ -214,12 +214,15 @@ class Taskbook { break; case 'done': + case 'check': case 'checked': case 'complete': data = this._filterComplete(data); break; case 'progress': + case 'start': + case 'doing': case 'started': case 'begun': data = this._filterInProgress(data); @@ -529,6 +532,32 @@ class Taskbook { render.markUnstarred(unstarred); } + swapItems(ids) { + ids = this._validateIDs(ids); + + if (ids.length > 2 ) { + render.invalidIDsNumber(); + process.exit(1); + } + + if (ids.length < 2) { + render.notEnoughIDsNumber(); + process.exit(1); + } + + const {_data} = this; + + _data[ids[0]]._id = ids[1]; + _data[ids[1]]._id = ids[0]; + + var tmp = _data[ids[0]]; + _data[ids[0]] = _data[ids[1]]; + _data[ids[1]] = tmp; + + this._save(_data); + render.swapSuccess(ids); + } + updatePriority(input) { const level = input.find(x => ['1', '2', '3'].indexOf(x) > -1);