diff --git a/README.md b/README.md index 0fdc5a2..5632f3f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ hstr ==== -Shell command history suggest box for Bash and [Zsh](CONFIGURATION.md#zsh-history-settings). +Shell history suggest box for Bash and +[Zsh](CONFIGURATION.md#zsh-history-settings) - easily view, navigate, sort and use your command history. [![BASH History Suggest Box](http://mindforger.com/projects/images/hh-3.png "BASH History Suggest Box @ YouTube")](http://www.youtube.com/watch?v=sPF29NyXe2U) diff --git a/src/hstr_history.c b/src/hstr_history.c index 47ad8d7..af92cf0 100644 --- a/src/hstr_history.c +++ b/src/hstr_history.c @@ -129,8 +129,7 @@ HistoryItems *get_prioritized_history() if(!regexp_match(®exp, historyList[i]->line)) { continue; } - - if(line && strlen(historyList[i]->line)>itemOffset) { + if(historyList[i]->line && strlen(historyList[i]->line)>itemOffset) { line=historyList[i]->line+itemOffset; } else { line=historyList[i]->line; diff --git a/src/hstr_utils.c b/src/hstr_utils.c index 4c10f00..bdc15e3 100644 --- a/src/hstr_utils.c +++ b/src/hstr_utils.c @@ -126,17 +126,18 @@ void toggle_case(char *str, bool lowercase) { } } -const char* get_process_name_by_pid(const int pid) +char *get_process_name_by_pid(const int pid) { - char* name = (char*)calloc(256,sizeof(char)); + char* name = (char*)calloc(10,sizeof(char)); if(name){ sprintf(name, "/proc/%d/cmdline",pid); FILE* f = fopen(name,"r"); if(f){ - size_t size = fread(name, sizeof(char), 256, f); + size_t size = fread(name, sizeof(char), 10, f); if(size>0){ - if('\n'==name[size-1]) + if('\n'==name[size-1]) { name[size-1]='\0'; + } } fclose(f); } @@ -146,7 +147,7 @@ const char* get_process_name_by_pid(const int pid) bool isZshParentShell() { pid_t parentPid=getppid(); - const char* cmdline=get_process_name_by_pid(parentPid); + char* cmdline=get_process_name_by_pid(parentPid); bool result=cmdline && strstr(cmdline, "zsh"); free(cmdline); return result; diff --git a/src/include/hstr_utils.h b/src/include/hstr_utils.h index d2f3ce0..9b4bb72 100644 --- a/src/include/hstr_utils.h +++ b/src/include/hstr_utils.h @@ -11,6 +11,7 @@ #define _HSTR_UTILS_H #include +#include #include #include #include