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
|
||||
return $ret
|
||||
}
|
||||
function confirm() {
|
||||
CMD=$@
|
||||
echo "Execute: '$CMD' ?";
|
||||
function confirm_inner() {
|
||||
echo -n "[Y/n]: "
|
||||
# a weid difference between zsh and bash
|
||||
if [[ "$SHELL" =~ (.*zsh) ]]; then
|
||||
|
@ -144,11 +142,17 @@ function confirm() {
|
|||
read -s -n1;
|
||||
fi
|
||||
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;;
|
||||
* ) echo -e 'Invalid choice, aborted.'; return 2;;
|
||||
esac;
|
||||
}
|
||||
|
||||
function confirm() {
|
||||
CMD=$@
|
||||
echo "Execute: '$CMD' ?";
|
||||
confirm_inner $CMD
|
||||
}
|
||||
function confirm-important() {
|
||||
echo "Write 'yes do as i say' to confirm that you REALLY want to do this: $@"
|
||||
read
|
||||
|
@ -168,7 +172,23 @@ function writepatch() {
|
|||
nvim 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 -------------------------------------
|
||||
setopt autocd
|
||||
|
|
Loading…
Add table
Reference in a new issue