cspell icon indicating copy to clipboard operation
cspell copied to clipboard

🔍 Config resolution from a global path

Open bdsoha opened this issue 2 years ago • 7 comments

Is your feature request related to a problem? Please describe. The cspell tool can be installed globally (i.e. npm -g install ...), as well as executed from any directory. However, the configuration files cannot be defined globally.

Describe the solution you'd like I propose, that in addition to local configurations lookups, global lookups be included as well. For example, configurations could also be stored in

  • $HOME/.cspell.{yaml,json}
  • $HOME/.config/cspell/*

Describe alternatives you've considered Defining a global alias:

alias cspell='cspell --config=/home/.../.config/cspell/config.yaml'

bdsoha avatar Jan 17 '24 12:01 bdsoha

@bdsoha,

Will the cspell link command work for you?

cspell link --help

Usage: cspell link [options] [command]

Link dictionaries and other settings to the cspell global config.

Options:
  -h, --help               display help for command

Commands:
  list|ls                  List currently linked configurations.
  add|a <dictionaries...>  Add dictionaries any other settings to the cspell global config.
  remove|r <paths...>      Remove matching paths / packages from the global config.
  help [command]           display help for command

Using something like:

cspell link add ./cspell.config.yaml

Jason3S avatar Jan 21 '24 09:01 Jason3S

@Jason3S The suggested link command does indeed work. However, it requires additional (manual) steps to be executed by the user. I am suggested an automated (convention based) approach to the same solution.

bdsoha avatar Jan 21 '24 09:01 bdsoha

@bdsoha,

It is not exactly the same, but cspell does search up the directory structure looking for the configuration.

If you have a ~/.config/cspell.config.yaml file and you run cspell from ~/a/b/c, it will find the configuration as long as it does not find another one sooner.

Jason3S avatar Jan 21 '24 13:01 Jason3S

Another option would be to have cspell look at environment variables:

  • $CSPELL_DEFAULT_CONFIG_PATH - a path to the config to use if one is not found using the standard search method.
  • $CSPELL_CONFIG_PATH - a path the the config file to use as long as one has not been specified on the command line.

Edited based upon comment below.

Jason3S avatar Jan 21 '24 13:01 Jason3S

Also a great option, just be sure to use underscores: $CSPELL_DEFAULT_CONFIG_PATH

bdsoha avatar Jan 21 '24 13:01 bdsoha

Any updates on this?

bdsoha avatar Feb 08 '24 06:02 bdsoha

@bdsoha,

A PR is welcome if you would like to try.

This will most likely get done within the next three months. If it is urgent, consider a support contract: Street Side Software - Support.

Jason3S avatar Feb 09 '24 06:02 Jason3S