Skip to content

Commit cc57fc8

Browse files
committed
[Fix] - fixing bug when installing by home-brew
[Improvement] - update the document to make it more clear for how to use it [Improvement] - to comply shellcheck standard
1 parent 2058371 commit cc57fc8

2 files changed

Lines changed: 61 additions & 44 deletions

File tree

README.md

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# helpful-commandlines
2-
This is the repo to collect helpful commandlines that is used for mac and Linux OS.
3-
2+
This is the repo to collect helpful commandlines that is used for MAC OS.
43

54
## Setup dependencies
65
Notes: This document is for macos environment.
@@ -37,6 +36,7 @@ jq-1.6
3736

3837
## Setup lhs-helpful-commandlines
3938
### Setup from homebrew
39+
**It is easy to setup and run and don't want to change or optimize it**
4040
#### Install
4141
```
4242
brew tap lamhaison/formulae
@@ -45,34 +45,42 @@ brew install lamhaison/formulae/lhs-helpful-commandlines
4545
## Load when start an Iterm terminal
4646
Add these lines to ~/.bashrc or ~/.zshrc or ~/.bash_profile
4747
```
48-
source "$(which lhs-helpful-commandlines.sh)" "/opt/homebrew/Cellar/lhs-helpful-commandlines/$(brew info lhs-helpful-commandlines | head -1 | awk -F "stable " '{print $2}')" "${HOME}" "True"
49-
48+
source "$(which lhs-helpful-commandlines.sh)" "/opt/homebrew/Cellar/lhs-helpful-commandlines/$(brew info lhs-helpful-commandlines | head -1 | awk -F "stable " '{print $2}')" "True" "True"
5049
```
5150

52-
### Re-install the latest version
51+
### Re-install the latest version(If there are new versions)
5352
```
5453
brew uninstall lhs-helpful-commandlines
5554
brew untap lamhaison/formulae
5655
brew tap lamhaison/formulae
5756
brew install lamhaison/formulae/lhs-helpful-commandlines
57+
```
5858

59+
## Settings when open terminal (I am using Iterm2)
60+
**It is easy for you to custom your scripting to fix with your style**
5961

60-
## Settings when open terminal (I am using iterm)
6162
```
6263
mkdir -p /opt/lamhaison-tools && cd /opt/lamhaison-tools
6364
git clone https://github.com/lamhaison/helpful-commandlines.git
6465
echo "source /opt/lamhaison-tools/helpful-commandlines/main.sh" >> ~/.bashrc
6566
```
6667

67-
# How to search commandline
68+
# How to use it?
69+
70+
## How to search helpful commandline
71+
```
72+
Ctrl + h: to and choose the commandline that you want to run(searching and enter to auto fill it to your terminal)
73+
lhs_help_helpful cmd: only for searching, it will not automatically fill in to your terminal
6874
```
69-
Ctrl + H or lhs_help_helpful
70-
Option + R for search history commandline(As the same with sh-history-substring-search)
7175

76+
## How to search your history commandlines
77+
```
78+
Option + r: to select the history commandline that you wan to re-run(searching and enter to auto fill it to your terminal)
79+
search history commandline: only for searching history, it will not automatically fill in to your termial
7280
```
7381

74-
# How to enable git commit suggestions
82+
## How to enable git commit suggestions
7583
```
76-
Option + gc or lhs_git_commit_suggestions | peco
84+
lhs_git_commit_suggestions: only for searching the list commit message pattern
7785
```
7886

main.sh

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,36 +21,6 @@ else
2121
export HELPFUL_COMMANDLINES_SOURCE_SCRIPTS=${HELPFUL_COMMANDLINES_SOURCE_SCRIPTS}
2222
fi
2323

24-
# Extend for poco-select-history function
25-
# export HISTSIZE=20000
26-
# export SAVEHIST=15000
27-
# https://github.com/mattjj/my-oh-my-zsh/blob/master/history.zsh
28-
29-
LHS_CHANGE_HISTORY_SETTINGS=${3:-'True'}
30-
31-
if [[ "${LHS_CHANGE_HISTORY_SETTINGS}" = "True" && "$(which setopt)" != "" ]]; then
32-
export HISTFILE="$HOME/.zsh_history"
33-
export HISTSIZE=1048576
34-
export SAVEHIST=1048576
35-
# Ignore duplicates in command history and increase
36-
export HISTCONTROL=ignoredups
37-
38-
setopt BANG_HIST # Treat the '!' character specially during expansion.
39-
setopt EXTENDED_HISTORY # Write the history file in the ":start:elapsed;command" format.
40-
setopt INC_APPEND_HISTORY # Write to the history file immediately, not when the shell exits.
41-
setopt SHARE_HISTORY # Share history between all sessions.
42-
setopt HIST_EXPIRE_DUPS_FIRST # Expire duplicate entries first when trimming history.
43-
44-
setopt HIST_IGNORE_DUPS # Don't record an entry that was just recorded again.
45-
setopt HIST_IGNORE_ALL_DUPS # Delete old recorded entry if new entry is a duplicate.
46-
setopt HIST_FIND_NO_DUPS # Do not display a line previously found.
47-
setopt HIST_IGNORE_SPACE # Don't record an entry starting with a space.
48-
setopt HIST_SAVE_NO_DUPS # Don't write duplicate entries in the history file.
49-
setopt HIST_REDUCE_BLANKS # Remove superfluous blanks before recording entry.
50-
setopt HIST_VERIFY # Don't execute immediately upon history expansion.
51-
setopt HIST_BEEP # Beep when accessing nonexistent history.
52-
fi
53-
5424
export LHS_PROJECTS_DIR=~/projects
5525
# Get all history from folder /opt/lamhaison-tools
5626
export LHS_HELPFUL_LOOKUP="${HELPFUL_COMMANDLINES_SOURCE_SCRIPTS}/.."
@@ -62,20 +32,29 @@ export LHS_HELPFUL_LOOKUP_FUNCTIONS_CACHED_EXPIRED_TIME=$((60 * 8))
6232
# https://yukimemi.netlify.app/all-you-need-is-peco/
6333
# https://thevaluable.dev/zsh-line-editor-configuration-mouseless/
6434
for script in $(
65-
find ${HELPFUL_COMMANDLINES_SOURCE_SCRIPTS} -type f -name '*.sh' |
35+
find "${HELPFUL_COMMANDLINES_SOURCE_SCRIPTS}" -type f -name '*.sh' |
6636
grep -v -E '.*(main.sh|test.sh|temp.sh|helpful-commandlines.sh)$'
6737
); do
68-
source $script
38+
39+
# shellcheck disable=SC1090
40+
source "${script}"
6941
done
7042

7143
export lhs_cli_peco_input_expired_time=10
7244
export lhs_cli_show_commandline=true
7345
export lhs_cli_input=/tmp/lhs/inputs
7446
export lhs_cli_logs=/tmp/lhs/logs
75-
mkdir -p ${lhs_cli_input} ${lhs_cli_logs}
7647
export lhs_cli_log_file_path="${lhs_cli_logs}/lhs-cli.log"
7748
export lhs_cli_log_uploaded_file_path="${lhs_cli_logs}/lhs-cli-uploaded.log"
7849

50+
folder_list=("${lhs_cli_input}" "${lhs_cli_logs}")
51+
for folder in "${folder_list[@]}"; do
52+
if [ ! -d "$folder" ]; then
53+
mkdir -p "${folder}"
54+
fi
55+
done
56+
57+
# Setup binding keys
7958
LHS_BIND_KEY=${2:-'True'}
8059

8160
if [[ ${LHS_BIND_KEY} == "True" && "$(which zle)" != "" ]]; then
@@ -96,3 +75,33 @@ if [[ ${LHS_BIND_KEY} == "True" && "$(which zle)" != "" ]]; then
9675
# Hotkey: Option + gc
9776
bindkey '©ç' lhs_git_commit_suggestions_with_hint
9877
fi
78+
79+
# Setup for history commandlines feature
80+
# Extend for poco-select-history function
81+
# export HISTSIZE=20000
82+
# export SAVEHIST=15000
83+
# https://github.com/mattjj/my-oh-my-zsh/blob/master/history.zsh
84+
LHS_CHANGE_HISTORY_SETTINGS=${3:-'True'}
85+
86+
if [[ "${LHS_CHANGE_HISTORY_SETTINGS}" = "True" && "$(which setopt)" != "" ]]; then
87+
export HISTFILE="$HOME/.zsh_history"
88+
export HISTSIZE=1048576
89+
export SAVEHIST=1048576
90+
# Ignore duplicates in command history and increase
91+
export HISTCONTROL=ignoredups
92+
93+
setopt BANG_HIST # Treat the '!' character specially during expansion.
94+
setopt EXTENDED_HISTORY # Write the history file in the ":start:elapsed;command" format.
95+
setopt INC_APPEND_HISTORY # Write to the history file immediately, not when the shell exits.
96+
setopt SHARE_HISTORY # Share history between all sessions.
97+
setopt HIST_EXPIRE_DUPS_FIRST # Expire duplicate entries first when trimming history.
98+
99+
setopt HIST_IGNORE_DUPS # Don't record an entry that was just recorded again.
100+
setopt HIST_IGNORE_ALL_DUPS # Delete old recorded entry if new entry is a duplicate.
101+
setopt HIST_FIND_NO_DUPS # Do not display a line previously found.
102+
setopt HIST_IGNORE_SPACE # Don't record an entry starting with a space.
103+
setopt HIST_SAVE_NO_DUPS # Don't write duplicate entries in the history file.
104+
setopt HIST_REDUCE_BLANKS # Remove superfluous blanks before recording entry.
105+
setopt HIST_VERIFY # Don't execute immediately upon history expansion.
106+
setopt HIST_BEEP # Beep when accessing nonexistent history.
107+
fi

0 commit comments

Comments
 (0)