forked from desyncr/zpm-zsh
-
Notifications
You must be signed in to change notification settings - Fork 3
Zpm msg #33
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
Open
fennecdjay
wants to merge
5
commits into
zpm-project:master
Choose a base branch
from
fennecdjay:zpm_msg
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Zpm msg #33
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,23 @@ | ||
| After being disabled, plugin is not listed anymore | ||
| $ $ZPM reset | ||
| $ $ZPM "$ZPM_TEST_REPOS/example-plugin" > /dev/null | ||
| $ $ZPM disable "$ZPM_TEST_REPOS/example-plugin" > /dev/null | ||
| $ $ZPM "$ZPM_TEST_REPOS/example-plugin" > /dev/null 2>&1 | ||
| $ $ZPM disable "$ZPM_TEST_REPOS/example-plugin" > /dev/null 2>&1 | ||
| $ $ZPM list | ||
| Nothing to show. | ||
| [ZPM] Nothing to show. | ||
| [1] | ||
|
|
||
| Plugin directory is not removed after disable | ||
| $ $ZPM reset | ||
| $ $ZPM "$ZPM_TEST_REPOS/example-plugin" > /dev/null | ||
| $ $ZPM disable "$ZPM_TEST_REPOS/example-plugin" > /dev/null | ||
| $ $ZPM "$ZPM_TEST_REPOS/example-plugin" > /dev/null 2>&1 | ||
| $ $ZPM disable "$ZPM_TEST_REPOS/example-plugin" > /dev/null 2>&1 | ||
| $ ls $ZPM_TEST_REPOS | ||
| example-plugin | ||
| .* (re) | ||
|
|
||
| Plugin can be properly enabled/installed after "disable" | ||
| $ $ZPM reset | ||
| $ $ZPM "$ZPM_TEST_REPOS/example-plugin" > /dev/null | ||
| $ $ZPM disable "$ZPM_TEST_REPOS/example-plugin" > /dev/null | ||
| $ $ZPM "$ZPM_TEST_REPOS/example-plugin" > /dev/null | ||
| $ $ZPM "$ZPM_TEST_REPOS/example-plugin" > /dev/null 2>&1 | ||
| $ $ZPM disable "$ZPM_TEST_REPOS/example-plugin"> /dev/null 2>&1 | ||
| $ $ZPM "$ZPM_TEST_REPOS/example-plugin" > /dev/null 2>&1 | ||
| $ $ZPM list | ||
| .*example-plugin@.* (re) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ | |
| #include <errno.h> | ||
| #include <unistd.h> | ||
| #include <limits.h> | ||
|
|
||
| #include <stdarg.h> | ||
| #include <sys/types.h> | ||
| #include <dirent.h> | ||
| #include <sys/stat.h> | ||
|
|
@@ -19,6 +19,34 @@ | |
|
|
||
| static char zpm_init[PATH_MAX]; | ||
| static char zpm_list[PATH_MAX]; | ||
| static int zpm_has_color = 0; | ||
| static const char* zpm_usage = "Usage:\n\tzpm \"zsh-users/zsh-syntax-highlighting\"\n\tzpm disable \"zsh-users/zsh-syntax-highlighting\"\n\ | ||
| \tzpm remove \"zsh-users/zsh-syntax-highlighting\"\n\nAvailable commands:\n\tzpm reset\n\tzpm list\n\tzpm update\n\tzpm save\n\tzpm help\n\tzpm version"; | ||
|
|
||
| enum ZPM_MSG_TYPE { | ||
| ZPM_MSG, | ||
| ZPM_ERR, | ||
| ZPM_LOG, | ||
| ZPM_DEBUG, | ||
| ZPM_NONE | ||
| }; | ||
|
|
||
| void zpm_msg(enum ZPM_MSG_TYPE type, const char* fmt, ...) { | ||
| char msg[PATH_MAX]; | ||
| FILE* f = type == ZPM_ERR ? stderr : stdout; | ||
| va_list arg; | ||
| va_start(arg, fmt); | ||
| vsnprintf(msg, 256, fmt, arg); | ||
| if (type != ZPM_NONE) { | ||
| if(zpm_has_color) { | ||
| int color = type == ZPM_ERR ? 31 : 32; | ||
| fprintf(f, "\033[1m[\033[0m\033[%imZPM\033[0m\033[1m]\033[0m ", color); | ||
| } else { | ||
| fprintf(f, "[ZPM] "); | ||
| } | ||
| } fprintf(f, "%s", msg); | ||
| va_end(arg); | ||
| } | ||
|
|
||
| char* generate_plugin_path(char* plugin_name) { | ||
| if (plugin_name[0] == '/') { | ||
|
|
@@ -270,7 +298,6 @@ char* generate_repository_url(char* plugin_name) { | |
| } else { | ||
| strcpy(url, plugin_name); | ||
| } | ||
|
|
||
|
|
||
| return url; | ||
| } | ||
|
|
@@ -329,10 +356,10 @@ int plugins_update_local_clone() { | |
| char* plugin_name = strtok(listing, "\n"); | ||
|
|
||
| if (!strcmp(listing, "Nothing to show.")) { | ||
| printf("Nothing to update."); | ||
| zpm_msg(ZPM_ERR, "Nothing to update."); | ||
| return 1; | ||
| } | ||
| printf("Updating plugins...\n"); | ||
| zpm_msg(ZPM_MSG, "Updating plugins...\n"); | ||
| while (plugin_name) { | ||
| if (plugin_name[0] == '/') { | ||
| plugin_name = strtok(NULL, "\n"); | ||
|
|
@@ -341,7 +368,7 @@ int plugins_update_local_clone() { | |
| strcpy(command, "cd ~/.zpm/plugins/"); | ||
| strcat(command, plugin_name); | ||
| strcat(command, "; git pull"); | ||
| printf("Updating %s...\n", plugin_name); | ||
| zpm_msg(ZPM_MSG, "Updating %s...\n", plugin_name); | ||
| ret = system(command); | ||
| plugin_name = strtok(NULL, "\n"); | ||
| } | ||
|
|
@@ -350,11 +377,7 @@ int plugins_update_local_clone() { | |
| } | ||
|
|
||
| int usage(char* ret) { | ||
| printf("%s\n", "Usage:\n\tzpm \"zsh-users/zsh-syntax-highlighting\""); | ||
| printf("%s\n", "\tzpm disable \"zsh-users/zsh-syntax-highlighting\""); | ||
| printf("%s\n", "\tzpm remove \"zsh-users/zsh-syntax-highlighting\""); | ||
| printf("%s\n", "\nAvailable commands:\n\tzpm reset\n\tzpm list"); | ||
| printf("%s\n", "\tzpm update\n\tzpm save\n\tzpm help\n\tzpm version"); | ||
| zpm_msg(ZPM_NONE, "%s\n", zpm_usage); | ||
| return ret ? 0 : 1; | ||
| } | ||
|
|
||
|
|
@@ -380,7 +403,7 @@ char* plugin_get_hash(char* plugin_name) { | |
| fp = popen(command, "r"); | ||
| if (!fp) { | ||
| free(plugin_path); | ||
| printf("Failed to run command\n" ); | ||
| zpm_msg(ZPM_ERR, "Failed to run command\n" ); | ||
| return NULL; | ||
| } | ||
| fgets(plugin_hash, sizeof(plugin_hash), fp); | ||
|
|
@@ -394,18 +417,25 @@ int plugin_print_list() { | |
| char* plugin_name = strtok(listing, "\n"); | ||
|
|
||
| if (!strcmp(listing, "Nothing to show.")) { | ||
| printf("%s\n", listing); | ||
| zpm_msg(ZPM_MSG, "%s\n", listing); | ||
| free(listing); | ||
| return 1; | ||
| } | ||
| while (plugin_name) { | ||
| char* hash = plugin_get_hash(plugin_name); | ||
| printf("%s", plugin_name); | ||
| if (hash) { | ||
| printf("@%s", hash); | ||
| if(zpm_has_color) { | ||
| zpm_msg(ZPM_NONE, "\033[1m%s\033[0m@%s", plugin_name, hash); | ||
| } else { | ||
| zpm_msg(ZPM_NONE, "%s@%s", plugin_name, hash); | ||
| } | ||
| free(hash); | ||
| } else { | ||
| printf("\n"); | ||
| if(zpm_has_color) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the need to for this condition? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| zpm_msg(ZPM_NONE, "\033[1m%s\033[0m\n", plugin_name); | ||
| } else { | ||
| zpm_msg(ZPM_NONE, "%s\n", plugin_name); | ||
| } | ||
| } | ||
| plugin_name = strtok(NULL, "\n"); | ||
| } | ||
|
|
@@ -418,34 +448,34 @@ int plugin_print_script() { | |
| FILE* store = fopen(zpm_init, "r"); | ||
|
|
||
| if (!store) { | ||
| printf("Could not open \"%s\". Check the file exists and can be read.\n", zpm_init); | ||
| zpm_msg(ZPM_ERR, "Could not open \"%s\". Check the file exists and can be read.\n", zpm_init); | ||
| return 1; | ||
| } | ||
|
|
||
| memset(entry, 0, PATH_MAX); | ||
| while (fgets(entry, PATH_MAX, store)) { | ||
| char plugin[PATH_MAX]; | ||
| strncpy(plugin, entry, strlen(entry) -1); | ||
| printf("zpm \"%s\"\n", plugin); | ||
| zpm_msg(ZPM_NONE, "zpm \"%s\"\n", plugin); | ||
| } | ||
| fclose(store); | ||
| return 0; | ||
| } | ||
|
|
||
| int plugin_remove_entry(char* plugin_name, char* file_name) { | ||
| if (!plugin_name) { | ||
| printf("remove/uninstall command needs argument.\n"); | ||
| zpm_msg(ZPM_ERR, "remove/uninstall command needs argument.\n"); | ||
| return 1; | ||
| } | ||
| FILE* store = fopen(file_name, "r"); | ||
| if (!store) { | ||
| printf("Could not open \"%s\". Check the file exists and can be read.\n", file_name); | ||
| zpm_msg(ZPM_ERR,"Could not open \"%s\". Check the file exists and can be read.\n", file_name); | ||
| return 1; | ||
| } | ||
|
|
||
| FILE* tmp = fopen("/tmp/.zpm_tmp", "w"); | ||
| if (!tmp) { | ||
| printf("Could not open \"%s\". Check the file can be written.\n", "/tmp/.zpm_tmp"); | ||
| zpm_msg(ZPM_ERR, "Could not open \"%s\". Check the file can be written.\n", "/tmp/.zpm_tmp"); | ||
| return 1; | ||
| } | ||
|
|
||
|
|
@@ -473,11 +503,11 @@ int plugin_remove_entry(char* plugin_name, char* file_name) { | |
|
|
||
| int plugin_remove(char* plugin_name, int uninstall) { | ||
| if (!plugin_name) { | ||
| printf("remove needs an argument.\n"); | ||
| zpm_msg(ZPM_ERR, "remove needs an argument.\n"); | ||
| return 1; | ||
| } | ||
| if (!plugin_entry_exists(plugin_name)) { | ||
| printf("Plugin \"%s\" is not installed.\n", plugin_name); | ||
| zpm_msg(ZPM_ERR, "Plugin \"%s\" is not installed.\n", plugin_name); | ||
| return 1; | ||
| } | ||
| plugin_remove_entry(plugin_name, zpm_init); | ||
|
|
@@ -512,32 +542,30 @@ void zpm_config_init() { | |
|
|
||
| strcpy(zpm_list, home); | ||
| strcat(zpm_list, "/.zpm/plugin_list"); | ||
|
|
||
| zpm_has_color = getenv("ZPM_COLOR") ? 1 : 0; | ||
| } | ||
|
|
||
| int plugin_install(char* plugin_name) { | ||
| int status = strstr(plugin_name, "/") ? 0 : -1; | ||
| char install[PATH_MAX]; | ||
|
|
||
|
|
||
| if (plugin_entry_exists(plugin_name)) { | ||
| printf("Plugin \"%s\" already installed.\n", plugin_name); | ||
| zpm_msg(ZPM_ERR, "Plugin \"%s\" already installed.\n", plugin_name); | ||
| return 1; | ||
| } | ||
| strcpy(install, "Installing "); | ||
| strcat(install, plugin_name); | ||
| strcat(install, "... "); | ||
| printf("%s", install); | ||
| zpm_msg(ZPM_MSG, "Installing %s... ", plugin_name); | ||
| fflush(stdout); | ||
|
|
||
| if (local_clone_exists(plugin_name) == 1) { | ||
| status = locally_clone_plugin(plugin_name); | ||
| } | ||
|
|
||
| if (status == 0) { | ||
| printf("%s\n", "Done."); | ||
| zpm_msg(ZPM_NONE, "%s\n", "Done."); | ||
| generate_plugin_entry(plugin_name); | ||
| plugin_list_add_item(plugin_name); | ||
| } else { | ||
| printf("%s\n", "Error!"); | ||
| zpm_msg(ZPM_NONE, "%s\n", "Error!"); | ||
| } | ||
| return status; | ||
| } | ||
|
|
@@ -563,7 +591,7 @@ int main(int argc, char* argv[]) { | |
| } else if (strstr(argv[1], "help")) { | ||
| return usage(argv[1]); | ||
| } else if (strstr(argv[1], "version")) { | ||
| printf("%s\n", ZPM_VERSION); | ||
| zpm_msg(ZPM_MSG, "%s\n", ZPM_VERSION); | ||
| return 0; | ||
| } else { | ||
| return plugin_install(argv[1]); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check coding style.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, I mostly pasted untested code from the issue, so while fixing I forgot that 😕