{"action":"created","issue":{"url":"https://api.github.com/repos/Bash-it/bash-it/issues/944","repository_url":"https://api.github.com/repos/Bash-it/bash-it","labels_url":"https://api.github.com/repos/Bash-it/bash-it/issues/944/labels{/name}","comments_url":"https://api.github.com/repos/Bash-it/bash-it/issues/944/comments","events_url":"https://api.github.com/repos/Bash-it/bash-it/issues/944/events","html_url":"https://github.com/Bash-it/bash-it/issues/944","id":223714032,"number":944,"title":"Discussion: Bash-it Alias/Plugin/Completion Load Priority","user":{"login":"nwinkler","id":907063,"avatar_url":"https://avatars1.githubusercontent.com/u/907063?v=4","gravatar_id":"","url":"https://api.github.com/users/nwinkler","html_url":"https://github.com/nwinkler","followers_url":"https://api.github.com/users/nwinkler/followers","following_url":"https://api.github.com/users/nwinkler/following{/other_user}","gists_url":"https://api.github.com/users/nwinkler/gists{/gist_id}","starred_url":"https://api.github.com/users/nwinkler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nwinkler/subscriptions","organizations_url":"https://api.github.com/users/nwinkler/orgs","repos_url":"https://api.github.com/users/nwinkler/repos","events_url":"https://api.github.com/users/nwinkler/events{/privacy}","received_events_url":"https://api.github.com/users/nwinkler/received_events","type":"User","site_admin":false},"labels":[{"id":77740834,"url":"https://api.github.com/repos/Bash-it/bash-it/labels/New%20Features","name":"New Features","color":"009800","default":false}],"state":"open","locked":false,"assignee":{"login":"nwinkler","id":907063,"avatar_url":"https://avatars1.githubusercontent.com/u/907063?v=4","gravatar_id":"","url":"https://api.github.com/users/nwinkler","html_url":"https://github.com/nwinkler","followers_url":"https://api.github.com/users/nwinkler/followers","following_url":"https://api.github.com/users/nwinkler/following{/other_user}","gists_url":"https://api.github.com/users/nwinkler/gists{/gist_id}","starred_url":"https://api.github.com/users/nwinkler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nwinkler/subscriptions","organizations_url":"https://api.github.com/users/nwinkler/orgs","repos_url":"https://api.github.com/users/nwinkler/repos","events_url":"https://api.github.com/users/nwinkler/events{/privacy}","received_events_url":"https://api.github.com/users/nwinkler/received_events","type":"User","site_admin":false},"assignees":[{"login":"nwinkler","id":907063,"avatar_url":"https://avatars1.githubusercontent.com/u/907063?v=4","gravatar_id":"","url":"https://api.github.com/users/nwinkler","html_url":"https://github.com/nwinkler","followers_url":"https://api.github.com/users/nwinkler/followers","following_url":"https://api.github.com/users/nwinkler/following{/other_user}","gists_url":"https://api.github.com/users/nwinkler/gists{/gist_id}","starred_url":"https://api.github.com/users/nwinkler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nwinkler/subscriptions","organizations_url":"https://api.github.com/users/nwinkler/orgs","repos_url":"https://api.github.com/users/nwinkler/repos","events_url":"https://api.github.com/users/nwinkler/events{/privacy}","received_events_url":"https://api.github.com/users/nwinkler/received_events","type":"User","site_admin":false}],"milestone":null,"comments":2,"created_at":"2017-04-24T06:19:49Z","updated_at":"2017-09-17T19:46:08Z","closed_at":null,"author_association":"OWNER","body":"# Work in Progress\r\n\r\nSorry for the long post...\r\n\r\nThe work on this feature can be tracked in the [load-priority branch in my Bash-it fork](https://github.com/nwinkler/bash-it/tree/load-priority) for the first part, and the [enabled-global branch](https://github.com/nwinkler/bash-it/tree/enabled-global) for the second half. I will create a pull request on the main Bash-it repo once the implementation has been completed (see #974 for the first half and #1043 for the second half).\r\n\r\nPlease feel free to provide comments on this feature - especially @tswicegood, @edubxb, @revans and @thedrow. Others are of course welcome, too.\r\n\r\n# Problem Statement\r\n\r\nOne recurring problem (see #688 and #841 for examples) has been that Bash-it loads its components in a predefined order and does not allow to define dependencies between the components.\r\n\r\nThe fixed order for loading the components is\r\n\r\n* aliases\r\n* plugins\r\n* completions\r\n\r\nThis leads to the following problems, with two different flavors:\r\n\r\n* Within the same kind (e.g. plugins), load order is determined by alphabetical order, which means that the `node` plugin is loaded before the `nvm` plugin. When using `nvm` to install and run Node.js, `nvm` needs to be loaded first to make the `node` command available. With the current load order of Bash-it, this is not possible.\r\n* Dependencies between different kinds of components do not work. One example is the `alias-completion` plugin, which tries to enable shell completions for aliases. Since plugins are loaded before completions, the plugin does not find any completions that it could apply to the defined aliases. The current fix for this is to either move the plugin to the `custom` folder, or to run `reload` after Bash-it has loaded.\r\n\r\nThere are probably more examples than these two.\r\n\r\n# Solution Approach\r\n\r\nThe approach described here tries to address the two main problems described above.\r\n\r\n## Load Order\r\n\r\n(Implemented in #974)\r\n\r\nTo address the problem with a load order that's not purely based on the component's name, we are going to introduce a numeric value that determines the order in which the files are loaded.\r\n\r\nWith the current approach, the component (e.g. the `nvm` plugin) is linked into the `plugins/enabled` folder as `nvm.plugin.bash`. To break up the dependency on the plugin name for load order, a three digit numeric value will be introduced when creating the link, e.g `250---nvm.plugin.bash`.\r\n\r\nUsing a format like this for the link will allow to tailor the order of loading the files since the order will be based on the numeric value instead of the name, and the three dashes will allow to parse the name, separating the number from the name of the plugin.\r\n\r\nBy default, each type of component will have a default priority, preventing us from having to update all of the files:\r\n\r\n* Aliases: `150`\r\n* Plugins: `250`\r\n* Completions: `350`\r\n\r\nThese values allow for adjusting individual components up or down. To specify a different load priority for a component, we will introduce an optional comment value in the component file, which allows to override the default priority:\r\n\r\n```bash\r\n# BASH_IT_LOAD_PRIORITY: 999\r\n```\r\n\r\nIf this value is found in a component's file while enabling the component, it will be used instead of the default priority.\r\n\r\nTo implement this, the following areas of Bash-it have to be touched:\r\n\r\n* Enable Component will need to parse the component file and then create the link in the new format.\r\n* Show Components will need to parse the name of the links in the `enabled` folder to display which ones are enabled.\r\n* Disable Components will need to find the component to disable.\r\n\r\nThis solves the first problem by allowing to specify that the `nvm` plugin should be loaded before the `node` plugin:\r\n\r\n* The `nvm` plugin uses a custom priority, with a lower value than the default for plugins, e.g. `225`.\r\n* The `node` plugin uses the default priority of `250`.\r\n\r\nIf both are enabled, it will look like this:\r\n\r\n* `225---nvm.plugin.bash`\r\n* `250---node.plugin.bash`\r\n\r\n## One Common \"Enabled\" Directory\r\n\r\n(Implemented in #1043)\r\n\r\nThe second problem of having a predefined order of the different component types (first aliases, then plugins, then completions), is caused by the fact that each of the components has their own `enabled` directory, which is then loaded in turn by the `bash_it.sh` script.\r\n\r\nTo break up this fixed order, we are going to introduce a common `enabled` directory that will replace the individual directories. It's going to be placed at `$BASH_IT/enabled`\r\n\r\nSame as above the Enable, Show and Disable functionalities will have to be adjusted to make this work, using the common directory instead of the individual ones.\r\n\r\nThere should not be any naming conflicts, since the component files use an individual extension, e.g. `.plugin.bash` for plugins.\r\n\r\n### Backwards-Compatibility\r\n\r\nTo allow existing installations to work, the common `enabled` directory will be loaded before the current loop that loads aliases, plugins and completions. Existing installations that do not yet use the common directory will continue to work without any changes, while installations that already use the common directory will also work once all of the components have been migrated to the common directory.\r\n\r\n### Migration\r\n\r\nWe will add a `bash-it migrate` command that moves the symbolic links of the enabled components from the individual directories to the new common directory.\r\n\r\nIn addition to this, the `migrate` command will automatically run whenever the user enables a new component. This will ensure that existing installations will continue to work without changes, but once the user enables new functionality, the existing components will be migrated.\r\n\r\nThe `migrate` command will display a message to tell the user how many items were migrated to the new common `enabled` directory.\r\n\r\n# Tasks\r\n\r\nI'm probably going to commit this a two separate Pull Requests, where the first one will introduce the load priority, but still use the individual directories, and then the second one will move everything into a common `enabled` directory.\r\n\r\nSome of the tasks that I'm aware of - I'll try to provide unit tests where they make sense:\r\n\r\n# Load Order\r\n\r\n(Implemented in #974)\r\n\r\n- [x] `bash-it enable` a single component\r\n- [x] `bash-it enable` all components\r\n- [x] `bash-it disable` a single component\r\n- [x] `bash-it disable` all components\r\n- [x] Install script (it uses its own enabling code)\r\n- [x] Completion needs to consider the new and the old syntax\r\n- [x] Add `bash-it migrate` command\r\n- [x] Automatically run `bash-it migrate` when enabling/disabling something\r\n- [x] Update help/documentation\r\n- [x] Fix usage of `enabled` directory in existing code, e.g. plugins and themes\r\n- [x] Merge code (#974)\r\n\r\n# One Common \"Enabled\" Directory\r\n\r\n(Implemented in #1043)\r\n\r\n- [x] `bash-it enable` a single component\r\n- [x] `bash-it enable` all components\r\n- [x] `bash-it disable` a single component\r\n- [x] `bash-it disable` all components\r\n- [x] Install script (it uses its own enabling code)\r\n- [x] Completion needs to consider the new and the old location\r\n- [x] Update `bash-it migrate` command to move enabled components to the new common directory\r\n- [x] Automatically run `bash-it migrate` when enabling/disabling something\r\n- [x] Update help/documentation\r\n- [x] Update the `bash_it.sh` code to load the global `enabled` directory's content\r\n- [x] Move/refactor/test the `command_exist` function so that there is no hidden dependency from the main code on this function from the `base` plugin. (Fixes #1009)\r\n- [x] Merge code (#1043)"},"comment":{"url":"https://api.github.com/repos/Bash-it/bash-it/issues/comments/330078397","html_url":"https://github.com/Bash-it/bash-it/issues/944#issuecomment-330078397","issue_url":"https://api.github.com/repos/Bash-it/bash-it/issues/944","id":330078397,"user":{"login":"nwinkler","id":907063,"avatar_url":"https://avatars1.githubusercontent.com/u/907063?v=4","gravatar_id":"","url":"https://api.github.com/users/nwinkler","html_url":"https://github.com/nwinkler","followers_url":"https://api.github.com/users/nwinkler/followers","following_url":"https://api.github.com/users/nwinkler/following{/other_user}","gists_url":"https://api.github.com/users/nwinkler/gists{/gist_id}","starred_url":"https://api.github.com/users/nwinkler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nwinkler/subscriptions","organizations_url":"https://api.github.com/users/nwinkler/orgs","repos_url":"https://api.github.com/users/nwinkler/repos","events_url":"https://api.github.com/users/nwinkler/events{/privacy}","received_events_url":"https://api.github.com/users/nwinkler/received_events","type":"User","site_admin":false},"created_at":"2017-09-17T19:46:08Z","updated_at":"2017-09-17T19:46:08Z","author_association":"OWNER","body":"Implemented the second half in #1043 - reviews welcome!"}}
{"actor":{"display_login":"nwinkler"}}