-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.sh
114 lines (95 loc) · 4.17 KB
/
main.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/bash
#
# @version 1.0
# @script main.sh
# @description TODO : to load function for helpful-commandlines
# $1: Where is looking for sh files and source the list
# $2: Do you want to set the bind key?
# $3: To change history settings
HELPFUL_COMMANDLINES_SOURCE_SCRIPTS=$1
if [[ -z "${HELPFUL_COMMANDLINES_SOURCE_SCRIPTS}" ]]; then
# Get the current directory of the main.sh script.
LOCAL_HELPFUL_COMMANDLINES_SOURCE_SCRIPTS=$(dirname -- "$0")
if [[ "${LOCAL_HELPFUL_COMMANDLINES_SOURCE_SCRIPTS}" = "." ]]; then
DEFAULT_HELPFUL_COMMANDLINES_SOURCE_SCRIPTS='/opt/lamhaison-tools/helpful-commandlines'
fi
export HELPFUL_COMMANDLINES_SOURCE_SCRIPTS="${LOCAL_HELPFUL_COMMANDLINES_SOURCE_SCRIPTS:-${DEFAULT_HELPFUL_COMMANDLINES_SOURCE_SCRIPTS}}"
else
export HELPFUL_COMMANDLINES_SOURCE_SCRIPTS=${HELPFUL_COMMANDLINES_SOURCE_SCRIPTS}
fi
export LHS_PROJECTS_DIR=~/projects
# Get all history from folder /opt/lamhaison-tools
export LHS_HELPFUL_LOOKUP="${HELPFUL_COMMANDLINES_SOURCE_SCRIPTS}/.."
export LHS_HELPFUL_LOOKUP_CACHED=true
# Time for caching function suggestion menu in minutes
export LHS_HELPFUL_LOOKUP_FUNCTIONS_CACHED_EXPIRED_TIME=$((60 * 8))
# Import sub-commandline.
# 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' |
grep -v -E '.*(main.sh|test.sh|temp.sh|helpful-commandlines.sh)$'
); do
# 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
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"
# For peco settings
# --initial-filter IgnoreCase|CaseSensitive|SmartCase|Regexp|Fuzzy
# Only for history
export LHS_PECO_FILTER_HISTORY_TYPE=${4:-'IgnoreCase'}
# For global
export LHS_PECO_FILTER_TYPE=${5:-'IgnoreCase'}
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
# Add hot-keys
zle -N lhs_peco_select_history
# Using zsh-history-substring-search reserved
# bindkey '^r' lhs_peco_select_history
# Option + r
bindkey '®' lhs_peco_select_history
zle -N lhs_help_all
bindkey '^h' lhs_help_all
# Hot key for git commit suggestions
zle -N lhs_git_commit_suggestions_with_hint
# 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