Skip to content

Commit 748670d

Browse files
committed
[Fix] - merge conflict
2 parents 19b1388 + cc57fc8 commit 748670d

14 files changed

Lines changed: 238 additions & 111 deletions

File tree

README.md

Lines changed: 20 additions & 13 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.
@@ -11,7 +10,7 @@ brew install glab
1110
export GITLAB_TOKEN=xxxxx
1211
```
1312

14-
### Install Github cli
13+
### Install GitHub cli
1514
```
1615
brew install gh
1716
export GH_TOKEN=xxxx
@@ -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,41 @@ 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
5857
```
5958

60-
## Settings when open terminal (I am using iterm)
59+
## Settings when open terminal (I am using Iterm2)
60+
**It is easy for you to custom your scripting to fix with your style**
61+
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-
```
69-
Ctrl + H for search list commandline
70-
Option + R for search history
68+
# How to use it?
7169

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
7274
```
7375

74-
# How to enable git commit suggestions
76+
## How to search your history commandlines
7577
```
76-
Option + gc or lhs_git_commit_suggestions | peco
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
7780
```
7881

82+
## How to enable git commit suggestions
83+
```
84+
lhs_git_commit_suggestions: only for searching the list commit message pattern
85+
```

common/help_ips.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ function lhs_network_get_public_ip() {
99
dig +short myip.opendns.com @resolver1.opendns.com
1010
}
1111

12-
function lhs_what_is_my_ip() {
13-
lhs_network_get_public_ip
14-
}
15-
1612
function lhs_network_tcp_traceroute() {
1713

1814
# https://www.redhat.com/sysadmin/traceroute-finding-meaning

common/help_menu.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,11 @@ function lhs_help_all() {
1717
CURSOR=$#BUFFER
1818

1919
}
20+
21+
function lhs_help_refresh() {
22+
lhs_peco_disable_input_cached
23+
lhs_peco_function_list >>/dev/null
24+
lhs_peco_helpful_function_list >>/dev/null
25+
lhs_peco_enable_input_cached
26+
27+
}

common/other.sh

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,7 @@ function lhs_help_install_macos_peco_instruction() {
1515

1616
}
1717

18-
function lhs_help_hotkey_sublime_search_files_instruction() {
19-
cat <<-_EOF_
20-
# Search file in sublimetext on macos
21-
⌘(Command) + P
22-
_EOF_
23-
}
24-
25-
lhs_help_create_os_user_instruction() {
18+
function lhs_help_create_os_user_instruction() {
2619

2720
echo '
2821
@@ -45,3 +38,8 @@ lhs_help_create_os_user_instruction() {
4538
4639
'
4740
}
41+
42+
function lhs_help_cache_disabled_all() {
43+
lhs_peco_disable_input_cached
44+
peco_aws_disable_input_cached
45+
}

common/peco/other.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,24 @@
33
function lhs_peco_function_list() {
44
# Ignore private function
55
local lhs_function_list_cmd="
6-
find ${LHS_HELPFUL_LOOKUP} -type f -name '*.sh' | grep -v main.sh | xargs cat | grep -v '^function.*private.*' \
6+
find ${LHS_HELPFUL_LOOKUP} -type f -name '*.sh' \
7+
-not -path \"${LHS_HELPFUL_LOOKUP}/private-helpful-commandlines/tmp/*\" \
8+
-not -path \"${LHS_HELPFUL_LOOKUP}/dotfiles/*\" \
9+
| grep -v main.sh | xargs cat | grep -v '^function.*private.*' \
710
| grep -e '^function.*\(.+*\)' -e '^aws*\(.+*\)' -e '^peco*\(.+*\)' -e '^lhs*\(.+*\)' \
811
| tr -d '(){' | awk -F ' ' '{ print (\$1==\"function\") ? \$2 : \$1}' | sort
912
"
10-
# Cache in 1 minute
11-
lhs_peco_commandline_input "${lhs_function_list_cmd}" "${LHS_HELPFUL_LOOKUP_CACHED}" "1"
13+
# Cache in LHS_HELPFUL_LOOKUP_FUNCTIONS_CACHED_EXPIRED_TIME setting
14+
lhs_peco_commandline_input "${lhs_function_list_cmd}" "${LHS_HELPFUL_LOOKUP_CACHED}" "${LHS_HELPFUL_LOOKUP_FUNCTIONS_CACHED_EXPIRED_TIME}"
1215

1316
}
1417

1518
function lhs_peco_helpful_function_list() {
1619
local lhs_function_list_cmd="
17-
find ${HELPFUL_COMMANDLINES_SOURCE_SCRIPTS} -type f -name '*.sh' | grep -v main.sh | xargs cat | grep -e '^function.*\(.+*\)' -e '^aws*\(.+*\)' -e '^peco*\(.+*\)' -e '^lhs*\(.+*\)' \
20+
find ${HELPFUL_COMMANDLINES_SOURCE_SCRIPTS} -type f -name '*.sh' \
21+
-not -path \"${LHS_HELPFUL_LOOKUP}/private-helpful-commandlines/tmp/*\" \
22+
-not -path \"${LHS_HELPFUL_LOOKUP}/dotfiles/*\" \
23+
| grep -v main.sh | xargs cat | grep -e '^function.*\(.+*\)' -e '^aws*\(.+*\)' -e '^peco*\(.+*\)' -e '^lhs*\(.+*\)' \
1824
| tr -d '(){' | awk -F ' ' '{ print (\$1==\"function\") ? \$2 : \$1}' | sort
1925
"
2026

common/peco/peco.sh

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function lhs_peco_select_history() {
1010
fi
1111
BUFFER=$(history -n 1 | uniq |
1212
eval $tac |
13-
peco --query "$LBUFFER")
13+
peco --query "$LBUFFER" --initial-filter Regexp)
1414
# Move the cursor at then end of the input($#variable_name is to get the length itself)
1515
CURSOR=$#BUFFER
1616
# zle clear-screen
@@ -26,7 +26,14 @@ function lhs_peco_repo_list() {
2626
find ${LHS_PROJECTS_DIR} -type d -name '.git' -maxdepth 6 \
2727
| awk -F '/' '{for (i=1; i<NF; i++) printf \$i \"/\"; print '\n'}'" 'true' '60'
2828
)
29-
input_project=$(echo ${project_list} | peco)
29+
local final_projects=$(
30+
cat <<-__EOF__
31+
${LHS_TOOLS_DIR}
32+
${project_list}
33+
__EOF__
34+
)
35+
36+
input_project=$(echo ${final_projects} | peco)
3037
echo ${input_project}
3138
}
3239

@@ -56,17 +63,26 @@ function lhs_peco_disable_input_cached() {
5663
export lhs_cli_peco_input_expired_time=0
5764
}
5865

66+
function lhs_peco_enable_input_cached() {
67+
export lhs_cli_peco_input_expired_time=10
68+
}
69+
5970
function lhs_peco_run_command_to_get_input() {
6071
peco_commandline=$1
6172
eval ${peco_commandline}
6273
}
6374

6475
function lhs_peco_commandline_input() {
6576

66-
commandline="${1}"
77+
local commandline="${1}"
6778
local result_cached=${2:-'false'}
6879
local input_expired_time="${3:-$lhs_cli_peco_input_expired_time}"
6980

81+
# To disable caching
82+
if [ "$lhs_cli_peco_input_expired_time" = "0" ]; then
83+
input_expired_time=0
84+
fi
85+
7086
local md5_hash=$(echo $commandline | md5)
7187
local input_folder="${lhs_cli_input:-/tmp/inputs}"
7288
mkdir -p ${input_folder}
@@ -85,7 +101,7 @@ function lhs_peco_commandline_input() {
85101
local format_text=$(lhs_peco_format_output_text $commandline_result)
86102

87103
if [ -n "${format_text}" ]; then
88-
commandline=$(lhs_util_format_commandline_one_line ${commandline})
104+
commandline=$(local_lhs_util_format_commandline_one_line ${commandline})
89105
echo "******** [ ${commandline} ] ********" >${input_file_path}
90106
echo ${format_text} | tee -a ${input_file_path}
91107
else

common/utils.sh

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,44 @@
11
#!/bin/bash
22

33
# Get DateTime
4-
function lhs_date_get_with_format() {
4+
5+
function lhs_cmd_date_get_month() {
6+
date +%m
7+
}
8+
9+
function lhs_cmd_date_get_year() {
10+
date +%Y
11+
}
12+
function lhs_cmd_date_get_with_format() {
513
echo $(date "+"${1:-"%Y-%m-%d-%H-%M-%S"})
614
}
715

8-
function lhs_date_get_with_format_yyyymmdd() {
9-
lhs_date_get_with_format "%Y%m%d"
16+
function lhs_cmd_date_get_with_format_yyyymmdd() {
17+
lhs_cmd_date_get_with_format "%Y%m%d"
18+
}
19+
20+
function lhs_cmd_date_get_with_format_cw_log() {
21+
lhs_cmd_date_get_with_format "%Y-%m-%d %H:%M:%S"
22+
}
23+
24+
function lhs_cmd_date_get_epoch_time() {
25+
# unix-time-in-milliseconds
26+
date -d '0 hour ago' +%s%N | cut -b1-13
27+
}
28+
29+
# TODO function lhs_cmd_time_convert_echo_to_human_readable_formaton_name to convert epoch time to human readable formnat.
30+
# @param $1: the value of epoch time and $2: the formant(default is %Y-%m-%d-%H-%M-%S)
31+
# @return
32+
#
33+
function lhs_cmd_time_convert_echo_to_human_readable_format() {
34+
35+
# TODO Later (it didn't work rightnow)
36+
local default_date_format=+${2:-'%Y-%m-%d-%H-%M-%S'}
37+
date -r ${1:?'epoch_value is unset or empty'} ${default_date_format}
1038
}
1139

1240
# Password generate
13-
function lhs_password_generate() {
41+
function lhs_cmd_password_generate() {
1442
# openssl rand -base64 10 | tr -d '='
1543

1644
cd /tmp >/dev/null
@@ -19,7 +47,7 @@ function lhs_password_generate() {
1947
}
2048

2149
# Get DateTime
22-
function lhs_file_name_get_random_name() {
50+
function lhs_cmd_file_name_get_random_name() {
2351
local file_name=${1:-'FILENAME'}
2452
cd /tmp >/dev/null
2553
mktemp ${file_name}-XXXXXXXXXXXXXX
@@ -44,7 +72,7 @@ function lhs_file_name_get_random_name() {
4472
# set +x
4573
# }
4674

47-
function lhs_run_commandline_with_retry() {
75+
function local_local_lhs_run_commandline_with_retry() {
4876
local lhs_commandline=$1
4977
local silent_mode=$2
5078
local retry_counter=0
@@ -75,25 +103,30 @@ function lhs_run_commandline_with_retry() {
75103

76104
}
77105

78-
function lhs_run_commandline() {
79-
lhs_run_commandline=$1
80-
lhs_run_commandline="${lhs_run_commandline:?'lhs_run_commandline is unset or empty'}"
81-
lhs_run_commandline_with_logging "${lhs_run_commandline}"
106+
function local_lhs_run_commandline() {
107+
local_lhs_run_commandline=$1
108+
local_lhs_run_commandline="${local_lhs_run_commandline:?'local_lhs_run_commandline is unset or empty'}"
109+
local_local_lhs_run_commandline_with_logging "${local_lhs_run_commandline}"
82110
}
83111

84-
function lhs_commandline_logging() {
112+
function local_lhs_commandline_logging() {
113+
114+
local log_file_path=${aws_cli_logs}/${ASSUME_ROLE}.log
115+
local tee_command="tee -a ${lhs_cli_log_file_path}"
116+
85117
local eval_commandline=${2:-'False'}
86-
lhs_commandline_logging=$(echo ${1:?'lhs_commandline is unset or empty'} | tr -d '\t' | tr -d '\n')
118+
119+
local local_lhs_commandline_logging=$(echo ${1:?'lhs_commandline is unset or empty'} | tr -d '\t' | tr -d '\n')
87120

88121
if [[ "${eval_commandline}" == "True" ]]; then
89-
echo "${lhs_commandline_logging}"
122+
echo "${local_lhs_commandline_logging}"
90123
else
91-
echo "Running commandline [ ${lhs_commandline_logging} ]"
124+
echo "Running commandline [ ${local_lhs_commandline_logging} ]" | eval $tee_command
92125
fi
93126

94127
}
95128

96-
function lhs_run_commandline_with_logging() {
129+
function local_local_lhs_run_commandline_with_logging() {
97130
lhs_commandline=$1
98131
if [ "$lhs_show_log_uploaded" = "true" ]; then
99132
local tee_command="tee -a ${lhs_cli_log_file_path} ${lhs_cli_log_uploaded_file_path}"
@@ -108,18 +141,18 @@ function lhs_run_commandline_with_logging() {
108141
fi
109142

110143
echo "------------------------------STARTED--$(date '+%Y-%m-%d-%H-%M-%S')-----------------------------------------" | eval $tee_command >/dev/null
111-
lhs_commandline_logging $1 | eval $detail_commandline_tee_command
112-
lhs_commandline_result=$(lhs_run_commandline_with_retry "${lhs_commandline}" "${ignored_error_when_retry}")
144+
local_lhs_commandline_logging $1 | eval $detail_commandline_tee_command
145+
lhs_commandline_result=$(local_local_lhs_run_commandline_with_retry "${lhs_commandline}" "${ignored_error_when_retry}")
113146
echo $lhs_commandline_result | eval $tee_command
114147
echo "------------------------------FINISHED-$(date '+%Y-%m-%d-%H-%M-%S')-----------------------------------------" | eval $tee_command >/dev/null
115148
}
116149

117-
function lhs_util_rm_space() {
150+
function local_lhs_util_rm_space() {
118151
# echo "${1}" | sed 's/[[:space:]]//g'
119152
# https://stackoverflow.com/questions/13659318/how-to-remove-space-from-string
120153
echo "${1//+([[:space:]])/}"
121154
}
122155

123-
function lhs_util_format_commandline_one_line() {
156+
function local_lhs_util_format_commandline_one_line() {
124157
echo ${1} | tr -d '\t' | tr -d '\n' | tr -s ' '
125158
}

0 commit comments

Comments
 (0)