The Wayback Machine - https://web.archive.org/web/20201106193404/https://github.com/dsifford/yarn-completion/issues/47
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Targets with a : don't work correctly (special characters require escaping) #47

Closed
dkarlovi opened this issue Jun 1, 2020 · 12 comments
Closed

Comments

@dkarlovi
Copy link

@dkarlovi dkarlovi commented Jun 1, 2020

Example (generated by Nest.js CLI):

{
    "name": "hello-nest-js",
    "version": "0.0.1",
    "description": "",
    "author": "",
    "private": true,
    "license": "UNLICENSED",
    "scripts": {
        "prebuild": "rimraf dist",
        "build": "nest build",
        "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
        "start": "nest start",
        "start:dev": "nest start --watch",
        "start:debug": "nest start --debug --watch",
        "start:prod": "node dist/main",
        "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
        "test": "jest",
        "test:watch": "jest --watch",
        "test:cov": "jest --coverage",
        "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
        "test:e2e": "jest --config ./test/jest-e2e.json"
    },
    "dependencies": {
        "@nestjs/common": "^7.0.0",
        "@nestjs/core": "^7.0.0",
        "@nestjs/platform-express": "^7.0.0",
        "reflect-metadata": "^0.1.13",
        "rimraf": "^3.0.2",
        "rxjs": "^6.5.4"
    },
    "devDependencies": {
        "@nestjs/cli": "^7.0.0",
        "@nestjs/schematics": "^7.0.0",
        "@nestjs/testing": "^7.0.0",
        "@types/express": "^4.17.6",
        "@types/jest": "25.1.4",
        "@types/node": "^13.9.1",
        "@types/supertest": "^2.0.8",
        "@typescript-eslint/eslint-plugin": "^2.23.0",
        "@typescript-eslint/parser": "^2.23.0",
        "eslint": "^6.8.0",
        "eslint-config-prettier": "^6.10.0",
        "eslint-plugin-import": "^2.20.1",
        "jest": "^25.1.0",
        "prettier": "^1.19.1",
        "supertest": "^4.0.2",
        "ts-jest": "25.2.1",
        "ts-loader": "^6.2.1",
        "ts-node": "^8.6.2",
        "tsconfig-paths": "^3.9.0",
        "typescript": "^3.7.4"
    },
    "jest": {
        "moduleFileExtensions": [
            "js",
            "json",
            "ts"
        ],
        "rootDir": "src",
        "testRegex": ".spec.ts$",
        "transform": {
            "^.+\\.(t|j)s$": "ts-jest"
        },
        "coverageDirectory": "../coverage",
        "testEnvironment": "node"
    }
}

Sample:

$ yarn run <TAB><TAB>
build        lint         start:debug  test         test:e2e     
env          prebuild     start:dev    test:cov     test:watch   
format       start        start:prod   test:debug   
$ yarn run test<TAB><TAB>
test        test:cov    test:debug  test:e2e    test:watch  
$ yarn run test:<TAB><TAB>
$ yarn run test:c<TAB><TAB>overage 
yarn run v1.21.1
error Command "test:coverage" not found.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
@dsifford
Copy link
Owner

@dsifford dsifford commented Jun 1, 2020

I'm not sure I understand what the error here is.

There is not a test:coverage command. That is a valid error.

@dkarlovi
Copy link
Author

@dkarlovi dkarlovi commented Jun 1, 2020

It was autocompleted, for whatever reason. Notice that cov was not offered, for example.

Also, nothing gets completed with just test:.

@dkarlovi
Copy link
Author

@dkarlovi dkarlovi commented Jun 1, 2020

Oh, just figured out why coverage was completed, I have a folder named like that:

$ ls
coverage  nest-cli.json  package.json  src   tsconfig.build.json  yarn.lock
dist      node_modules   README.md     test  tsconfig.json
$ touch x123
$ yarn run test:x<TAB>123 ^C
@dsifford
Copy link
Owner

@dsifford dsifford commented Jun 1, 2020

Did you try the suggestion in the bottom of the readme?

@dkarlovi
Copy link
Author

@dkarlovi dkarlovi commented Jun 1, 2020

Just now (didn't notice it before). It behaves the same, only the options are presented differently. It would still complete coverage, for example.

@dsifford
Copy link
Owner

@dsifford dsifford commented Jun 1, 2020

Then yeah not sure I'm able to do anything about it. I tried looking into this in the past and came up short.

Happy to hear suggestions though.

@dsifford
Copy link
Owner

@dsifford dsifford commented Jun 1, 2020

I've got package.json files with a similar convention and have found it not a big deal to do yarn t<Tab><Tab><Tab> to get test:cov completed.

@dkarlovi
Copy link
Author

@dkarlovi dkarlovi commented Jun 1, 2020

@dsifford
Copy link
Owner

@dsifford dsifford commented Jun 1, 2020

Already do that

declare COMP_WORDBREAKS=$' \t\n"\'><=;|&(:'
@dkarlovi
Copy link
Author

@dkarlovi dkarlovi commented Jun 1, 2020

No, this specifically avoids redefining it, quote:

modifying COMP_WORDBREAKS in your completion script is not safe (as it is a global variable and it has the side effect of affecting the behavior of other completion scripts - for example scp).
Therefore, bash completion offers some helper methods which you can use to achieve your goal in a better and more safer way.

I've checked with Maven, which uses this and the difference is their completion escapes the character:

$ mvn <TAB><TAB>
assembly:assembly                  dependency:sources
clean                              dependency:tree
compile                            dependency:unpack
dependency:analyze                 dependency:unpack-dependencies
dependency:analyze-dep-mgt         deploy
dependency:analyze-duplicate       eclipse:eclipse
dependency:analyze-only            idea:idea
dependency:analyze-report          install
dependency:build-classpath         package
dependency:copy                    plexus:app
dependency:copy-dependencies       plexus:bundle-application
dependency:get                     plexus:bundle-runtime
dependency:go-offline              plexus:descriptor
dependency:list                    plexus:runtime
dependency:properties              plexus:service
dependency:purge-local-repository  site
dependency:resolve                 test/
dependency:resolve-plugins         verify
$ mvn depe<TAB>ndency\:<TAB>
dependency:analyze                 dependency:list
dependency:analyze-dep-mgt         dependency:properties
dependency:analyze-duplicate       dependency:purge-local-repository
dependency:analyze-only            dependency:resolve
dependency:analyze-report          dependency:resolve-plugins
dependency:build-classpath         dependency:sources
dependency:copy                    dependency:tree
dependency:copy-dependencies       dependency:unpack
dependency:get                     dependency:unpack-dependencies
dependency:go-offline              
$ mvn dependency\:ana<TAB>lyze<TAB>
dependency:analyze            dependency:analyze-only
dependency:analyze-dep-mgt    dependency:analyze-report
dependency:analyze-duplicate  
@dkarlovi
Copy link
Author

@dkarlovi dkarlovi commented Jun 1, 2020

Adding the backslash manually does work, I get test\:cov completed correctly (but it again removes the backslash).

Escaping special chars like colons, spaced etc would probably fix it without other changes.

@dkarlovi dkarlovi changed the title Targets with a : don't work correctly Targets with a : don't work correctly (they require escaping) Jun 1, 2020
@dkarlovi dkarlovi changed the title Targets with a : don't work correctly (they require escaping) Targets with a : don't work correctly (special characters require escaping) Jun 1, 2020
gluck added a commit to gluck/yarn-completion that referenced this issue Jun 24, 2020
- use same char escapes as npm (see `npm completion` output)
- avoid COMP_WORDBREAKS override
dsifford pushed a commit that referenced this issue Jun 29, 2020
- use same char escapes as npm (see `npm completion` output)
- avoid COMP_WORDBREAKS override
@dsifford
Copy link
Owner

@dsifford dsifford commented Jun 29, 2020

Fixed in #48

@dsifford dsifford closed this Jun 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.