docs: files, proxy, string
This commit is contained in:
parent
5ad80a8617
commit
bf83e02431
81
README.md
81
README.md
@ -21,10 +21,6 @@ python3 -m pip install --user --upgrade pynvim
|
|||||||
```sh
|
```sh
|
||||||
bash -c "`curl -fsSL https://raw.githubusercontent.com/ruilisi/dotar/master/install.sh`"
|
bash -c "`curl -fsSL https://raw.githubusercontent.com/ruilisi/dotar/master/install.sh`"
|
||||||
```
|
```
|
||||||
Or
|
|
||||||
```sh
|
|
||||||
bash -c "`curl -fsSL https://xiemala.com/ruilisi/dotar/raw/branch/master/install.sh`"
|
|
||||||
```
|
|
||||||
|
|
||||||
## Upgrade
|
## Upgrade
|
||||||
```sh
|
```sh
|
||||||
@ -34,35 +30,34 @@ rake update
|
|||||||
```
|
```
|
||||||
|
|
||||||
# Modules
|
# Modules
|
||||||
## ZSH
|
* ZSH
|
||||||
* [Prezto - the zsh behind YADR's](http://github.com/sorin-ionescu/prezto)
|
* [Prezto - the zsh behind YADR's](http://github.com/sorin-ionescu/prezto)
|
||||||
* [How to add your own ZSH theme](doc/zsh/themes.md)
|
* [How to add your own ZSH theme](doc/zsh/themes.md)
|
||||||
|
|
||||||
#### General Commands
|
## Zsh Commands
|
||||||
- `Replace`
|
#### [Files](./zsh/files.zsh)
|
||||||
- `Replace s SOURCE_TEXT -d DESTINATION_TEXT -f FILE_REGEX_PATTERH --separator=SEPERATOR`
|
Command | Args | Description
|
||||||
- By default, `FILE_REGEX_PATTERN` is `.*`, SEPERATOR` is `;`
|
:--------|:------|:-----------
|
||||||
- Example: `Replace -s "/api/rule" -d "/dashboard/api/rule" -f ".*.ts"`
|
swap | F1 F2 | swap file F1 with file F2
|
||||||
- `secure_source` -source `~/.yadr/zsh/function.zsh` file, let `function.zsh` modify work immediately in current window
|
Replace |[doc](#Replace) |Replace text recursively
|
||||||
- `pp $1` -useage:`pp xx`, grep process by name
|
|
||||||
- `set_proxy` -set terminal proxy use http proxy
|
|
||||||
- `set_vagrant_proxy` -set terminal proxy use vagrant http proxy
|
|
||||||
- `set_ss_proxy` -set terminal proxy use socks proxy
|
|
||||||
- `unset_proxy` -cancel all proxy
|
|
||||||
- `post $1 $2` -curl POST with application/json
|
|
||||||
- `git-set-remote $1` -set project git remote url
|
|
||||||
- `gem_source_to_taobao` -set ruby gem source to taobao
|
|
||||||
- `docker_rm_all` -delete all docker images
|
|
||||||
- `Replace $1 $2` -replcae all text under current path
|
|
||||||
- `swap $1 $2` -`swap file1 file2`
|
|
||||||
- `init_db` -init rails project database
|
|
||||||
- `kexec` -execute k8s pod by regex pod name
|
|
||||||
- `klog` -show k8s pod log by regex pod name
|
|
||||||
- `git_tag_delete` -delete gtihub tag
|
|
||||||
- `git_tag_add` -add gtihub tag
|
|
||||||
- `dc` -alias of docker-compose
|
|
||||||
|
|
||||||
#### Editing Commands
|
|
||||||
|
<a name="Replace">
|
||||||
|
Replace
|
||||||
|
</a>options:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
-f File regex pattern
|
||||||
|
-s Source pattern
|
||||||
|
-d Destination pattern
|
||||||
|
-r Remove line
|
||||||
|
--regex Match pattern with regex
|
||||||
|
--seperator= Seperator, # by default
|
||||||
|
-h Display this message"
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
#### Editing
|
||||||
Shortcut | Alias
|
Shortcut | Alias
|
||||||
:-----------|:--------
|
:-----------|:--------
|
||||||
Ctrl-R | Vim mode and bash style historical anti-query
|
Ctrl-R | Vim mode and bash style historical anti-query
|
||||||
@ -70,14 +65,14 @@ ae | Edit alias
|
|||||||
ar | Reload alias
|
ar | Reload alias
|
||||||
ESC C-x C-e |Edit current command line in vim
|
ESC C-x C-e |Edit current command line in vim
|
||||||
|
|
||||||
#### Network tools
|
#### Network
|
||||||
Command | Description
|
Command | Description
|
||||||
:-----------|:--------
|
:-----------|:--------
|
||||||
test-port PORT | test whether PORT is opened
|
test-port PORT | test whether PORT is opened
|
||||||
intercept-request-hosts | intercept requests and show hosts
|
intercept-request-hosts | intercept requests and show hosts
|
||||||
host-ip | show host ip of your system
|
host-ip | show host ip of your system
|
||||||
|
|
||||||
#### System commands
|
#### System
|
||||||
Command | Description
|
Command | Description
|
||||||
:-----------|:--------
|
:-----------|:--------
|
||||||
yell | print the script name and all arguments to stderr
|
yell | print the script name and all arguments to stderr
|
||||||
@ -85,13 +80,14 @@ die | does the same as yell, but exits with a non-0 exit status, which m
|
|||||||
try | uses the || (boolean OR), which only evaluates the right side if the left one didn’t fail.
|
try | uses the || (boolean OR), which only evaluates the right side if the left one didn’t fail.
|
||||||
list-large-files DIR | list large files sort by reversed order of size and print size in the order of `KB`, `MB`, `GB`
|
list-large-files DIR | list large files sort by reversed order of size and print size in the order of `KB`, `MB`, `GB`
|
||||||
|
|
||||||
#### String commands
|
#### String
|
||||||
Command | Description
|
Command | Description
|
||||||
:------------|:--------
|
:------------|:--------
|
||||||
random-hex | print random hex
|
random-hex | print random hex
|
||||||
random-string| print random string of alphabets `a-zA-Z0-9`
|
random-string| print random string of alphabets `a-zA-Z0-9`
|
||||||
|
contains |str1 str2 ... target |test whether a target string is included in an array of strings
|
||||||
|
|
||||||
#### Git Commands
|
#### Git
|
||||||
YADR will take over your ~/.gitconfig, so if you want to store your git username and other settings, please put them in ~/.gitconfig.user
|
YADR will take over your ~/.gitconfig, so if you want to store your git username and other settings, please put them in ~/.gitconfig.user
|
||||||
|
|
||||||
We recommend setting your user information in this file. In addition, you can set your environment variables appropriately in your ~/.secrets.
|
We recommend setting your user information in this file. In addition, you can set your environment variables appropriately in your ~/.secrets.
|
||||||
@ -121,6 +117,21 @@ Command | Alias
|
|||||||
`gsp` |`git stash pop`
|
`gsp` |`git stash pop`
|
||||||
`gst` |`git stash`
|
`gst` |`git stash`
|
||||||
|
|
||||||
|
#### Other
|
||||||
|
- `secure_source` -source `~/.yadr/zsh/function.zsh` file, let `function.zsh` modify work immediately in current window
|
||||||
|
- `pp $1` -useage:`pp xx`, grep process by name
|
||||||
|
- `set_proxy` -set terminal proxy use http proxy
|
||||||
|
- `set_vagrant_proxy` -set terminal proxy use vagrant http proxy
|
||||||
|
- `set_ss_proxy` -set terminal proxy use socks proxy
|
||||||
|
- `unset_proxy` -cancel all proxy
|
||||||
|
- `post $1 $2` -curl POST with application/json
|
||||||
|
- `docker_rm_all` -delete all docker images
|
||||||
|
- `kexec` -execute k8s pod by regex pod name
|
||||||
|
- `klog` -show k8s pod log by regex pod name
|
||||||
|
- `git_tag_delete` -delete gtihub tag
|
||||||
|
- `git_tag_add` -add gtihub tag
|
||||||
|
- `dc` -alias of docker-compose
|
||||||
|
|
||||||
## [fasd](https://github.com/clvv/fasd)
|
## [fasd](https://github.com/clvv/fasd)
|
||||||
The name fasd comes from the default suggested aliases f(files), a(files/directories), s(show/search/select), d(directories).
|
The name fasd comes from the default suggested aliases f(files), a(files/directories), s(show/search/select), d(directories).
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ done
|
|||||||
|
|
||||||
if [ ! -d "$HOME/.yadr" ]; then
|
if [ ! -d "$HOME/.yadr" ]; then
|
||||||
echo "Installing YADR for the first time"
|
echo "Installing YADR for the first time"
|
||||||
git clone --depth=1 https://github.com/ruilisi/dotfiles.git "$HOME/.yadr"
|
git clone --depth=1 https://github.com/ruilisi/dotar.git "$HOME/.yadr"
|
||||||
cd "$HOME/.yadr"
|
cd "$HOME/.yadr"
|
||||||
[ "$1" = "ask" ] && export ASK="true"
|
[ "$1" = "ask" ] && export ASK="true"
|
||||||
rake install
|
rake install
|
||||||
|
78
zsh/files.zsh
Normal file
78
zsh/files.zsh
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
swap() {
|
||||||
|
if [ $# -ne 2 ]; then
|
||||||
|
echo "Usage: swap file1 file2"
|
||||||
|
else
|
||||||
|
local TMPFILE=$(mktemp)
|
||||||
|
mv "$1" $TMPFILE
|
||||||
|
mv "$2" "$1"
|
||||||
|
mv $TMPFILE "$2"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Replace replaces non-regex pattern recursively
|
||||||
|
# Example: Replace 'ctx.Status(400)' "ctx.Status(http.StatusBadRequest)"
|
||||||
|
Replace () {
|
||||||
|
CMD=$0
|
||||||
|
function usage ()
|
||||||
|
{
|
||||||
|
echo "Usage : $CMD [options] [--]
|
||||||
|
Options:
|
||||||
|
-f File regex pattern
|
||||||
|
-s Source pattern
|
||||||
|
-d Destination pattern
|
||||||
|
-r Remove line
|
||||||
|
--regex Match pattern with regex
|
||||||
|
--seperator= Seperator, # by default
|
||||||
|
-h Display this message"
|
||||||
|
}
|
||||||
|
FILE_REGEX='.*'
|
||||||
|
SRC=""
|
||||||
|
DST=""
|
||||||
|
SEP=";"
|
||||||
|
DEBUG=false
|
||||||
|
REMOVE=false
|
||||||
|
REGEX=false
|
||||||
|
while getopts ":rhf:s:d:-:" opt
|
||||||
|
do
|
||||||
|
case "${opt}" in
|
||||||
|
-)
|
||||||
|
echo $OPTART
|
||||||
|
case "${OPTARG}" in
|
||||||
|
debug)
|
||||||
|
DEBUG=true
|
||||||
|
;;
|
||||||
|
regex)
|
||||||
|
REGEX=true
|
||||||
|
;;
|
||||||
|
seperator=*)
|
||||||
|
val=${OPTARG#*=}
|
||||||
|
SEP=$val
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Unknown option --${OPTARG}"
|
||||||
|
;;
|
||||||
|
esac;;
|
||||||
|
f) FILE_REGEX=$OPTARG ;;
|
||||||
|
r) REMOVE=true ;;
|
||||||
|
s) SRC=$OPTARG ;;
|
||||||
|
d) DST=$OPTARG ;;
|
||||||
|
h) usage; return 0 ;;
|
||||||
|
*) echo -e "\n option does not exist : $OPTARG\n";
|
||||||
|
usage; return 1 ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
SEARCH_CMD="ag `$REGEX || echo -Q` \"$SRC\" -l -G \"$FILE_REGEX\""
|
||||||
|
MATCHED_FILES=`eval "$SEARCH_CMD"`
|
||||||
|
echo "Replace in current files:$fg[green]\n$MATCHED_FILES$reset_color"
|
||||||
|
if $REMOVE; then
|
||||||
|
SED_CMD=\\${SEP}$SRC${SEP}d
|
||||||
|
else
|
||||||
|
SED_CMD=s${SEP}$SRC${SEP}$DST${SEP}g
|
||||||
|
fi
|
||||||
|
if [[ "$(uname)" == "Darwin" ]]; then
|
||||||
|
echo "xargs sed -i '' \"${SED_CMD}\""
|
||||||
|
echo $MATCHED_FILES | xargs sed -i '' "${SED_CMD}"
|
||||||
|
elif [[ "$(expr substr $(uname -s) 1 5)" == "Linux" ]]; then
|
||||||
|
echo $MATCHED_FILES | xargs sed -i ${SED_CMD}
|
||||||
|
fi
|
||||||
|
}
|
@ -5,18 +5,6 @@ function secure_source () {
|
|||||||
source $1
|
source $1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
function contains() {
|
|
||||||
local n=$#
|
|
||||||
local value=${!n}
|
|
||||||
for ((i=1;i < $#;i++)) {
|
|
||||||
if [ "${!i}" == "${value}" ]; then
|
|
||||||
echo "y"
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
echo "n"
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
pp() { ps aux | grep "$1\|USER" | grep -v "grep" }
|
pp() { ps aux | grep "$1\|USER" | grep -v "grep" }
|
||||||
function getIP () {
|
function getIP () {
|
||||||
echo $(grep $1 ~/.ssh/config -A 1 | tail -1 | tr -s ' ' | cut -d ' ' -f 3)
|
echo $(grep $1 ~/.ssh/config -A 1 | tail -1 | tr -s ' ' | cut -d ' ' -f 3)
|
||||||
@ -30,50 +18,12 @@ function ssh_exec_by_file () {
|
|||||||
ssh -t $1 "bash -s" -- < $2
|
ssh -t $1 "bash -s" -- < $2
|
||||||
}
|
}
|
||||||
|
|
||||||
function cp_container() {
|
|
||||||
sourceName=$1
|
|
||||||
targetName=$2
|
|
||||||
cp $sourceName $targetName -r
|
|
||||||
cd $targetName
|
|
||||||
mv ${sourceName}.scss ${targetName}.scss
|
|
||||||
mv ${sourceName}.js ${targetName}.js
|
|
||||||
cd ..
|
|
||||||
}
|
|
||||||
function set_proxy() {
|
|
||||||
export http_proxy=http://127.0.0.1:8668;export https_proxy=http://127.0.0.1:8668;
|
|
||||||
}
|
|
||||||
function set_vagrant_proxy() {
|
|
||||||
export http_proxy=http://127.0.0.1:9119;export https_proxy=http://127.0.0.1:9119;
|
|
||||||
}
|
|
||||||
function set_ss_proxy() {
|
|
||||||
export https_proxy=socks5://127.0.0.1:1080/
|
|
||||||
export http_proxy=socks5://127.0.0.1:1080/
|
|
||||||
}
|
|
||||||
function unset_proxy() {
|
|
||||||
unset all_proxy
|
|
||||||
unset http_proxy
|
|
||||||
unset https_proxy
|
|
||||||
}
|
|
||||||
function post {
|
function post {
|
||||||
curl -H "Content-Type: application/json" -X POST -d $1 $2
|
curl -H "Content-Type: application/json" -X POST -d $1 $2
|
||||||
}
|
}
|
||||||
function git-set-remote {
|
|
||||||
git remote rm origin
|
|
||||||
git remote rm upstream
|
|
||||||
git remote add origin $1
|
|
||||||
git remote add upstream $1
|
|
||||||
}
|
|
||||||
function search_installed_packages {
|
function search_installed_packages {
|
||||||
dpkg --get-selections | grep $1
|
dpkg --get-selections | grep $1
|
||||||
}
|
}
|
||||||
function delete_packages {
|
|
||||||
sudo apt remove `_search_installed_packages $1 | cut -f 1 | tr "\n" " "`
|
|
||||||
}
|
|
||||||
function gem_source_to_taobao {
|
|
||||||
gem source -r https://rubygems.org/
|
|
||||||
gem source -a https://ruby.taobao.org
|
|
||||||
}
|
|
||||||
|
|
||||||
function set_anonymous {
|
function set_anonymous {
|
||||||
git filter-branch --env-filter '
|
git filter-branch --env-filter '
|
||||||
if [ "$GIT_AUTHOR_NAME" = "ralletstellar" ]; then \
|
if [ "$GIT_AUTHOR_NAME" = "ralletstellar" ]; then \
|
||||||
@ -95,95 +45,15 @@ function strip_color() {
|
|||||||
function docker_rm_all() {
|
function docker_rm_all() {
|
||||||
docker rm -f `docker ps --no-trunc -aq`
|
docker rm -f `docker ps --no-trunc -aq`
|
||||||
}
|
}
|
||||||
# Replace replaces non-regex pattern recursively
|
|
||||||
# Example: Replace 'ctx.Status(400)' "ctx.Status(http.StatusBadRequest)"
|
|
||||||
function Replace () {
|
|
||||||
CMD=$0
|
|
||||||
function usage ()
|
|
||||||
{
|
|
||||||
echo "Usage : $CMD [options] [--]
|
|
||||||
Options:
|
|
||||||
-f File regex pattern
|
|
||||||
-s Source pattern
|
|
||||||
-d Destination pattern
|
|
||||||
-r Remove line
|
|
||||||
--regex Match pattern with regex
|
|
||||||
--seperator= Seperator, # by default
|
|
||||||
-h Display this message"
|
|
||||||
}
|
|
||||||
FILE_REGEX='.*'
|
|
||||||
SRC=""
|
|
||||||
DST=""
|
|
||||||
SEP=";"
|
|
||||||
DEBUG=false
|
|
||||||
REMOVE=false
|
|
||||||
REGEX=false
|
|
||||||
while getopts ":rhf:s:d:-:" opt
|
|
||||||
do
|
|
||||||
case "${opt}" in
|
|
||||||
-)
|
|
||||||
echo $OPTART
|
|
||||||
case "${OPTARG}" in
|
|
||||||
debug)
|
|
||||||
DEBUG=true
|
|
||||||
;;
|
|
||||||
regex)
|
|
||||||
REGEX=true
|
|
||||||
;;
|
|
||||||
seperator=*)
|
|
||||||
val=${OPTARG#*=}
|
|
||||||
SEP=$val
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Unknown option --${OPTARG}"
|
|
||||||
;;
|
|
||||||
esac;;
|
|
||||||
f) FILE_REGEX=$OPTARG ;;
|
|
||||||
r) REMOVE=true ;;
|
|
||||||
s) SRC=$OPTARG ;;
|
|
||||||
d) DST=$OPTARG ;;
|
|
||||||
h) usage; return 0 ;;
|
|
||||||
*) echo -e "\n option does not exist : $OPTARG\n";
|
|
||||||
usage; return 1 ;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
SEARCH_CMD="ag `$REGEX || echo -Q` \"$SRC\" -l -G \"$FILE_REGEX\""
|
|
||||||
MATCHED_FILES=`eval "$SEARCH_CMD"`
|
|
||||||
echo "Replace in current files:$fg[green]\n$MATCHED_FILES$reset_color"
|
|
||||||
if $REMOVE; then
|
|
||||||
SED_CMD=\\${SEP}$SRC${SEP}d
|
|
||||||
else
|
|
||||||
SED_CMD=s${SEP}$SRC${SEP}$DST${SEP}g
|
|
||||||
fi
|
|
||||||
if [[ "$(uname)" == "Darwin" ]]; then
|
|
||||||
echo "xargs sed -i '' \"${SED_CMD}\""
|
|
||||||
echo $MATCHED_FILES | xargs sed -i '' "${SED_CMD}"
|
|
||||||
elif [[ "$(expr substr $(uname -s) 1 5)" == "Linux" ]]; then
|
|
||||||
echo $MATCHED_FILES | xargs sed -i ${SED_CMD}
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
function git-change-module-remote() {
|
function git-change-module-remote() {
|
||||||
git config --file=.gitmodules submodule.$1.url $2
|
git config --file=.gitmodules submodule.$1.url $2
|
||||||
git config --file=.gitmodules submodule.$1.branch $3
|
git config --file=.gitmodules submodule.$1.branch $3
|
||||||
git submodule sync
|
git submodule sync
|
||||||
git submodule update --init --recursive --remote
|
git submodule update --init --recursive --remote
|
||||||
}
|
}
|
||||||
function replace() {
|
|
||||||
ag -l -G $1 | xargs sed -ri.bak -e "s/$2/$3/g"
|
|
||||||
}
|
|
||||||
function markdown-preview() {
|
function markdown-preview() {
|
||||||
cat $1 | instant-markdown-d > /dev/null 2>&1
|
cat $1 | instant-markdown-d > /dev/null 2>&1
|
||||||
}
|
}
|
||||||
function swap() {
|
|
||||||
if [ $# -ne 2 ]; then
|
|
||||||
echo "Usage: swap file1 file2"
|
|
||||||
else
|
|
||||||
local TMPFILE=$(mktemp)
|
|
||||||
mv "$1" $TMPFILE
|
|
||||||
mv "$2" "$1"
|
|
||||||
mv $TMPFILE "$2"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
function cmd_exists() {
|
function cmd_exists() {
|
||||||
$* &> /dev/null
|
$* &> /dev/null
|
||||||
if [[ $? == 0 ]]; then
|
if [[ $? == 0 ]]; then
|
||||||
|
15
zsh/proxy.zsh
Normal file
15
zsh/proxy.zsh
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
set_proxy() {
|
||||||
|
export http_proxy=http://127.0.0.1:8668;export https_proxy=http://127.0.0.1:8668;
|
||||||
|
}
|
||||||
|
set_vagrant_proxy() {
|
||||||
|
export http_proxy=http://127.0.0.1:9119;export https_proxy=http://127.0.0.1:9119;
|
||||||
|
}
|
||||||
|
set_ss_proxy() {
|
||||||
|
export https_proxy=socks5://127.0.0.1:1080/
|
||||||
|
export http_proxy=socks5://127.0.0.1:1080/
|
||||||
|
}
|
||||||
|
unset_proxy() {
|
||||||
|
unset all_proxy
|
||||||
|
unset http_proxy
|
||||||
|
unset https_proxy
|
||||||
|
}
|
@ -5,3 +5,16 @@ random-hex() {
|
|||||||
random-string() {
|
random-string() {
|
||||||
cat /dev/urandom | LC_ALL=C tr -dc 'a-zA-Z0-9' | fold -w ${1:-32} | head -n 1
|
cat /dev/urandom | LC_ALL=C tr -dc 'a-zA-Z0-9' | fold -w ${1:-32} | head -n 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
contains() {
|
||||||
|
local n=$#
|
||||||
|
local value=$@[n]
|
||||||
|
for ((i=1;i < $#;i++)) {
|
||||||
|
if [[ $@[i] == ${value} ]]; then
|
||||||
|
echo "yes"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
echo "no"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user