diff --git a/lib/plugins/console/new.js b/lib/plugins/console/new.js index 3b5942c98b..a73663e27f 100644 --- a/lib/plugins/console/new.js +++ b/lib/plugins/console/new.js @@ -2,6 +2,7 @@ const tildify = require('tildify'); const { magenta } = require('picocolors'); +const { basename } = require('path'); const reservedKeys = { _: true, @@ -21,16 +22,23 @@ const reservedKeys = { }; function newConsole(args) { - // Display help message if user didn't input any arguments - if (!args._.length) { + const path = args.p || args.path; + let title; + if (args._.length) { + title = args._.pop(); + } else if (path) { + // Default title + title = basename(path); + } else { + // Display help message if user didn't input any arguments return this.call('help', {_: ['new']}); } const data = { - title: args._.pop(), + title, layout: args._.length ? args._[0] : this.config.default_layout, slug: args.s || args.slug, - path: args.p || args.path + path }; const keys = Object.keys(args);