diff --git a/SE/bashrc.adoc b/SE/bashrc.adoc new file mode 100644 index 0000000000000000000000000000000000000000..3f5ac92d16e77255466add65bffc9210779140d9 --- /dev/null +++ b/SE/bashrc.adoc @@ -0,0 +1,35 @@ += Bashrc 实用技巧 + +== è·¯å¾„æ·»åŠ + +[source, shell] +---- +function add_to_path() { + local path_var_name="$1" + local new_path="$2" + + # Get the current value of the path variable + eval "current_paths=\${$path_var_name}" + + # Check if the new path is already in the path variable + if [[ ":$current_paths:" != *":$new_path:"* ]]; then + # If not present, append the new path to the end of the path variable + eval "export $path_var_name=\"\${current_paths:+\$current_paths:}$new_path\"" + fi +} + +# Usage example +add_to_path PATH "/usr/local/newpath" +---- + +== 设置编ç 为 UTF-8 + +[source, shell] +---- +if command -v locale &> /dev/null; then + if locale -a | grep -q "en_US.UTF-8"; then + export LANG=en_US.UTF-8 + export LC_ALL=en_US.UTF-8 + fi +fi +---- diff --git a/SE/git.adoc b/SE/git.adoc new file mode 100644 index 0000000000000000000000000000000000000000..e511043887db981d4e08c09797cb5ea8c59c7907 --- /dev/null +++ b/SE/git.adoc @@ -0,0 +1,49 @@ += git 使用技巧 + +== git 设置 http 自动转化为 ssh + +[source, shell] +---- +[url "ssh://git@gitlab.hinko.dev/"] + insteadOf = http://gitlab.hinko.dev/ +---- + +== my-amend: git commit --amend çš„æ›¿ä»£å“ + +[source, shell] +---- +[alias] + my-amend = "!f() { \ + git log -1; \ + if (( $? != 0 )); then \ + exit 1; \ + fi; \ + read -p \"Choose an option: (a) amend without message, (n) abort, (m) amend with new message, (c) commit with new message): \" choice; \ + case \"$choice\" in \ + a) git commit --amend --no-edit;; \ + n) echo \"Amend aborted\";; \ + m) git commit --amend;; \ + c) read -p \"Enter commit message (one line): \" commit_msg; git commit -m \"$commit_msg\";; \ + *) echo \"Invalid choice. Amend aborted.\"; exit 1;; \ + esac; \ + }; f" +---- + +== my-reset: åˆ é™¤å½“å‰æ‰€æœ‰éž main 分支,并更新 main 分支至远程仓库最新 + +[source, bash] +---- +[alias] + my-reset = "!f() { \ + git fetch --all; \ + if (( $? != 0 )); then \ + exit 1; \ + fi; \ + if [ \"$(git symbolic-ref --short -q HEAD)\" != \"main\" ]; then \ + git checkout main; \ + fi; \ + git branch | grep -v \"main\" | xargs git branch -D; \ + git reset --hard origin/main; \ + git clean -fdx; \ + }; f" +----