diff --git a/docs/api.md b/docs/api.md
index 85af99551..d18d8f935 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -813,6 +813,20 @@ var yargs = require("yargs")(['--info'])
.argv
```
+.scriptName($0)
+------------------
+
+Set the name of your script ($0). Default is the base filename executed by node (`process.argv[1]`)
+
+Example:
+
+```js
+var yargs = require("yargs")
+ .scriptName("my-script")
+ .help()
+ .argv
+```
+
.showHidden()
-----------------------------------------
.showHidden([option | boolean])
diff --git a/test/usage.js b/test/usage.js
index 8907e3529..6cfad3e75 100644
--- a/test/usage.js
+++ b/test/usage.js
@@ -1232,6 +1232,26 @@ describe('usage tests', () => {
})
})
+ describe('scriptName', () => {
+ it('should display user supplied scriptName', () => {
+ const r = checkUsage(() => yargs(['--help'])
+ .scriptName('custom')
+ .command('command')
+ .parse()
+ )
+ r.logs.join('\n').split(/\n+/).should.deep.equal([
+ 'custom [command]',
+ 'Commands:',
+ ' custom command',
+ 'Options:',
+ ' --help Show help [boolean]',
+ ' --version Show version number [boolean]'
+ ])
+ r.errors.should.have.length(0)
+ r.exit.should.equal(true)
+ })
+ })
+
it('should succeed when rebase', () => {
rebase(['home', 'chevex'].join(path.sep), ['home', 'chevex', 'foo', 'bar', 'baz'].join(path.sep)).should.equal(['foo', 'bar', 'baz'].join(path.sep))
rebase(['home', 'chevex', 'foo', 'bar', 'baz'].join(path.sep), ['home', 'chevex'].join(path.sep)).should.equal(['..', '..', '..'].join(path.sep))
diff --git a/yargs.js b/yargs.js
index da1a4bdbe..c2ac0fe98 100644
--- a/yargs.js
+++ b/yargs.js
@@ -37,6 +37,11 @@ function Yargs (processArgs, cwd, parentRequire) {
if (!cwd) cwd = process.cwd()
+ self.scriptName = function scriptName (scriptName) {
+ self.$0 = scriptName
+ return self
+ }
+
self.$0 = process.argv
.slice(0, 2)
.map((x, i) => {