Skip to content

Commit

Permalink
[Fix] - fixing bug when installing by home-brew
Browse files Browse the repository at this point in the history
[Improvement] - update the document to make it more clear for how to use
it
[Improvement] - to comply shellcheck standard
  • Loading branch information
lamhaison committed Oct 29, 2023
1 parent 2058371 commit cc57fc8
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 44 deletions.
30 changes: 19 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# helpful-commandlines
This is the repo to collect helpful commandlines that is used for mac and Linux OS.

This is the repo to collect helpful commandlines that is used for MAC OS.

## Setup dependencies
Notes: This document is for macos environment.
Expand Down Expand Up @@ -37,6 +36,7 @@ jq-1.6

## Setup lhs-helpful-commandlines
### Setup from homebrew
**It is easy to setup and run and don't want to change or optimize it**
#### Install
```
brew tap lamhaison/formulae
Expand All @@ -45,34 +45,42 @@ brew install lamhaison/formulae/lhs-helpful-commandlines
## Load when start an Iterm terminal
Add these lines to ~/.bashrc or ~/.zshrc or ~/.bash_profile
```
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"
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"
```

### Re-install the latest version
### Re-install the latest version(If there are new versions)
```
brew uninstall lhs-helpful-commandlines
brew untap lamhaison/formulae
brew tap lamhaison/formulae
brew install lamhaison/formulae/lhs-helpful-commandlines
```

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

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

# How to search commandline
# How to use it?

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

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

# How to enable git commit suggestions
## How to enable git commit suggestions
```
Option + gc or lhs_git_commit_suggestions | peco
lhs_git_commit_suggestions: only for searching the list commit message pattern
```

75 changes: 42 additions & 33 deletions main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,6 @@ else
export HELPFUL_COMMANDLINES_SOURCE_SCRIPTS=${HELPFUL_COMMANDLINES_SOURCE_SCRIPTS}
fi

# Extend for poco-select-history function
# export HISTSIZE=20000
# export SAVEHIST=15000
# https://github.com/mattjj/my-oh-my-zsh/blob/master/history.zsh

LHS_CHANGE_HISTORY_SETTINGS=${3:-'True'}

if [[ "${LHS_CHANGE_HISTORY_SETTINGS}" = "True" && "$(which setopt)" != "" ]]; then
export HISTFILE="$HOME/.zsh_history"
export HISTSIZE=1048576
export SAVEHIST=1048576
# Ignore duplicates in command history and increase
export HISTCONTROL=ignoredups

setopt BANG_HIST # Treat the '!' character specially during expansion.
setopt EXTENDED_HISTORY # Write the history file in the ":start:elapsed;command" format.
setopt INC_APPEND_HISTORY # Write to the history file immediately, not when the shell exits.
setopt SHARE_HISTORY # Share history between all sessions.
setopt HIST_EXPIRE_DUPS_FIRST # Expire duplicate entries first when trimming history.

setopt HIST_IGNORE_DUPS # Don't record an entry that was just recorded again.
setopt HIST_IGNORE_ALL_DUPS # Delete old recorded entry if new entry is a duplicate.
setopt HIST_FIND_NO_DUPS # Do not display a line previously found.
setopt HIST_IGNORE_SPACE # Don't record an entry starting with a space.
setopt HIST_SAVE_NO_DUPS # Don't write duplicate entries in the history file.
setopt HIST_REDUCE_BLANKS # Remove superfluous blanks before recording entry.
setopt HIST_VERIFY # Don't execute immediately upon history expansion.
setopt HIST_BEEP # Beep when accessing nonexistent history.
fi

export LHS_PROJECTS_DIR=~/projects
# Get all history from folder /opt/lamhaison-tools
export LHS_HELPFUL_LOOKUP="${HELPFUL_COMMANDLINES_SOURCE_SCRIPTS}/.."
Expand All @@ -62,20 +32,29 @@ export LHS_HELPFUL_LOOKUP_FUNCTIONS_CACHED_EXPIRED_TIME=$((60 * 8))
# https://yukimemi.netlify.app/all-you-need-is-peco/
# https://thevaluable.dev/zsh-line-editor-configuration-mouseless/
for script in $(
find ${HELPFUL_COMMANDLINES_SOURCE_SCRIPTS} -type f -name '*.sh' |
find "${HELPFUL_COMMANDLINES_SOURCE_SCRIPTS}" -type f -name '*.sh' |
grep -v -E '.*(main.sh|test.sh|temp.sh|helpful-commandlines.sh)$'
); do
source $script

# shellcheck disable=SC1090
source "${script}"
done

export lhs_cli_peco_input_expired_time=10
export lhs_cli_show_commandline=true
export lhs_cli_input=/tmp/lhs/inputs
export lhs_cli_logs=/tmp/lhs/logs
mkdir -p ${lhs_cli_input} ${lhs_cli_logs}
export lhs_cli_log_file_path="${lhs_cli_logs}/lhs-cli.log"
export lhs_cli_log_uploaded_file_path="${lhs_cli_logs}/lhs-cli-uploaded.log"

folder_list=("${lhs_cli_input}" "${lhs_cli_logs}")
for folder in "${folder_list[@]}"; do
if [ ! -d "$folder" ]; then
mkdir -p "${folder}"
fi
done

# Setup binding keys
LHS_BIND_KEY=${2:-'True'}

if [[ ${LHS_BIND_KEY} == "True" && "$(which zle)" != "" ]]; then
Expand All @@ -96,3 +75,33 @@ if [[ ${LHS_BIND_KEY} == "True" && "$(which zle)" != "" ]]; then
# Hotkey: Option + gc
bindkey '©ç' lhs_git_commit_suggestions_with_hint
fi

# Setup for history commandlines feature
# Extend for poco-select-history function
# export HISTSIZE=20000
# export SAVEHIST=15000
# https://github.com/mattjj/my-oh-my-zsh/blob/master/history.zsh
LHS_CHANGE_HISTORY_SETTINGS=${3:-'True'}

if [[ "${LHS_CHANGE_HISTORY_SETTINGS}" = "True" && "$(which setopt)" != "" ]]; then
export HISTFILE="$HOME/.zsh_history"
export HISTSIZE=1048576
export SAVEHIST=1048576
# Ignore duplicates in command history and increase
export HISTCONTROL=ignoredups

setopt BANG_HIST # Treat the '!' character specially during expansion.
setopt EXTENDED_HISTORY # Write the history file in the ":start:elapsed;command" format.
setopt INC_APPEND_HISTORY # Write to the history file immediately, not when the shell exits.
setopt SHARE_HISTORY # Share history between all sessions.
setopt HIST_EXPIRE_DUPS_FIRST # Expire duplicate entries first when trimming history.

setopt HIST_IGNORE_DUPS # Don't record an entry that was just recorded again.
setopt HIST_IGNORE_ALL_DUPS # Delete old recorded entry if new entry is a duplicate.
setopt HIST_FIND_NO_DUPS # Do not display a line previously found.
setopt HIST_IGNORE_SPACE # Don't record an entry starting with a space.
setopt HIST_SAVE_NO_DUPS # Don't write duplicate entries in the history file.
setopt HIST_REDUCE_BLANKS # Remove superfluous blanks before recording entry.
setopt HIST_VERIFY # Don't execute immediately upon history expansion.
setopt HIST_BEEP # Beep when accessing nonexistent history.
fi

0 comments on commit cc57fc8

Please sign in to comment.