recursive edit
This commit is contained in:
parent
18b60c9692
commit
fc13da5260
1 changed files with 25 additions and 5 deletions
30
.zshrc
30
.zshrc
|
@ -133,9 +133,7 @@ else
|
||||||
fi
|
fi
|
||||||
return $ret
|
return $ret
|
||||||
}
|
}
|
||||||
function confirm() {
|
function confirm_inner() {
|
||||||
CMD=$@
|
|
||||||
echo "Execute: '$CMD' ?";
|
|
||||||
echo -n "[Y/n]: "
|
echo -n "[Y/n]: "
|
||||||
# a weid difference between zsh and bash
|
# a weid difference between zsh and bash
|
||||||
if [[ "$SHELL" =~ (.*zsh) ]]; then
|
if [[ "$SHELL" =~ (.*zsh) ]]; then
|
||||||
|
@ -144,11 +142,17 @@ function confirm() {
|
||||||
read -s -n1;
|
read -s -n1;
|
||||||
fi
|
fi
|
||||||
case "${REPLY}" in
|
case "${REPLY}" in
|
||||||
y|Y|$'\n'|" "|"A"|"" ) echo yes;eval $CMD;;
|
y|Y|$'\n'|" "|"A"|"" ) echo yes; eval $@;;
|
||||||
n|N ) echo no;echo 'Aborted.' ; return 1;;
|
n|N ) echo no;echo 'Aborted.' ; return 1;;
|
||||||
* ) echo -e 'Invalid choice, aborted.'; return 2;;
|
* ) echo -e 'Invalid choice, aborted.'; return 2;;
|
||||||
esac;
|
esac;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function confirm() {
|
||||||
|
CMD=$@
|
||||||
|
echo "Execute: '$CMD' ?";
|
||||||
|
confirm_inner $CMD
|
||||||
|
}
|
||||||
function confirm-important() {
|
function confirm-important() {
|
||||||
echo "Write 'yes do as i say' to confirm that you REALLY want to do this: $@"
|
echo "Write 'yes do as i say' to confirm that you REALLY want to do this: $@"
|
||||||
read
|
read
|
||||||
|
@ -168,7 +172,23 @@ function writepatch() {
|
||||||
nvim b/$fname
|
nvim b/$fname
|
||||||
diff -Naru --color='auto' a/$fname b/$fname
|
diff -Naru --color='auto' a/$fname b/$fname
|
||||||
}
|
}
|
||||||
|
function recursive_file_sed ()
|
||||||
|
{
|
||||||
|
USAGE="USAGE: $0 FILE_ENDING REGEX"
|
||||||
|
ENDING=$1
|
||||||
|
REGEX=$2
|
||||||
|
if [[ -z $ENDING ]]; then
|
||||||
|
echo $USAGE
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
if [[ -z $REGEX ]]; then
|
||||||
|
echo $USAGE
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
echo "Are you SURE you want to recursively change all files with the ending '$ENDING' in $PWD with this regex: $REGEX ?"
|
||||||
|
confirm_inner
|
||||||
|
find $PWD -type f -name "*.$ENDING" | xargs sed -i "$REGEX"
|
||||||
|
}
|
||||||
|
|
||||||
### ---- zsh options -------------------------------------
|
### ---- zsh options -------------------------------------
|
||||||
setopt autocd
|
setopt autocd
|
||||||
|
|
Loading…
Add table
Reference in a new issue