dalance / amber Goto Github PK
View Code? Open in Web Editor NEWA code search / replace tool
License: MIT License
A code search / replace tool
License: MIT License
In this example I'm wanting ambr to search and replace only in file ihtemp
.
This works fine for a replacement string, like so:
[nix-shell:~/code/touchpage/elm]$ cp index.html.template ihttemp
[nix-shell:~/code/touchpage/elm]$ ambr --no-recursive {{elm-main}} wat ihttemp
/home/bburdette/code/touchpage/elm/ihttemp: <script type="text/javascript">{{elm-main}}></script>
Replace keyword? [Y]es/[n]o/[a]ll/[q]uit: y
Found .gitignore at the parent directory: "/home/bburdette/code/touchpage"
But with --rep-file the command also does a search and replace on index.html.template
.
[nix-shell:~/code/touchpage/elm]$ cp index.html.template ihttemp
[nix-shell:~/code/touchpage/elm]$ ambr --no-recursive {{elm-main}} --rep-file ../static/main.js ihttemp
/home/bburdette/code/touchpage/elm/ihttemp: <script type="text/javascript">{{elm-main}}></script>
Replace keyword? [Y]es/[n]o/[a]ll/[q]uit: y
/home/bburdette/code/touchpage/elm/index.html.template: <script type="text/javascript">{{elm-main}}></script>
Replace keyword? [Y]es/[n]o/[a]ll/[q]uit: n
Found .gitignore at the parent directory: "/home/bburdette/code/touchpage"
The Freedesktop standard has an environment variable XDG_CONFIG_DIRS
which sets the location for config directories. On Linux for example it's usually under ~/.config/
. It's nice to keep all the config files in one place and avoid cluttering the home dir.
The workflow would be faster if one didn't have to press Enter after choosing the action with y/n/a/q, similar as in other tools with such prompts.
sometimes, instead of wanting to replace a text with another, I want to delete the entire line of a matched value. Adding support to this would be great!
Hi,
for some of the sets of files I'm working with, the files' mtime is important.
But when I need to perform some refactoring with them, I want their timestamps to be preserved.
I'm familiar with the other modern search & replacement tools (namely Fastmod and Ruplacer), and oddly enough none of them offers this feature.
Therefore, I'd be much interested if Amber implemented it.
Cheers, and thanks for your work !
Sorry to tell you but I'm struggling with the configuration of amber
for different reasons :
Enable .gitignore skip
, do we enable to skip .gitignore
and search for ignored files or we enable to skip the files that are in .gitignore
?--key-from-file
, should we specify a filename (in which case it is probably an option
and not a flag
) or should we use some default filename?amr/s.toml
. Example: --skip-gitignore
is "disabled" by default and we "enable" it with this flag, but skip_gitignore
in .toml
is true
("enabled") by default. So it looks like that this two defaults are opposite to each other..toml
config and we want to disable them by flag ? If this is possible (by putting for example =false
) this should be documented..toml
are only valid for ambr
but not for ambs
and the documentation do not specify this. Example: interactive
.Suggestions about the .toml
configs:
.amber.toml
with sections for ambs
and ambr
for the specific flags. Example:skipped = true # valid for ambr and ambs
[ambr]
interactive = false # only for ambr
[ambs]
skip_gitignore = false # only for ambs
.toml
config files in multiple folders, for example (in order) :
.gitignore
)~/.config/amber
~/.config/
~
As of now, the LTO is disabled for the release build. Is this intentional?
Suggestion: When ambr is used with --regex, show the replacement that will be used.
So that the user can check if the given substitution expr was correct, before replacing everything..
Windows 7, ambr 0.5.8
$ ambr.exe -r ">\.\.\b" ">..."
thread 'replacer' panicked at 'called `Option::unwrap()` on a `None` value', src\pipeline_replacer.rs:222:45
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Using Amber v0.5.5 (precompiled binary) on Ubuntu 20.04, and testing it against Ripgrep 11.0.2.
Doing
f=$(tempfile)
echo Test > $f
ambs -r -- 'Test$' "$f"
outputs nothing, while
rg -s --no-heading --with-filename --no-line-number -- 'Test$' "$f"
outputs
/tmp/fileyO3IXf:Test
I do the following:
$ ambr foo bar
q
to quitstty sane
every is back to normal.stty
shows the following setting that where not there before calling amber:
min = 1; time = 0;
-icanon -echo
I'm using the current git-version install on Arch by the AUR package.
It would be helpful if amber provided also support for renaming files.
There is a common tool called rename
(from the linux-utils package), but it doesn't support regex.
On the other hand, simply doing a for loop in bash is error prone (non-interactive & requires working bash knowledge) and doesn't support recursion.
Thus, I think that it would be a nice functionality for amber to provide. Any chances?
It would be great to be able to install amber with Homebrew on macOS. Please provide a way to do that.
Suggestion: Show line number in ambr, when stepping through the matches.
Hi dev team,
just wanted to say that this package rocks, it's basically a core util for me at this point. I'm always recommending it to friends and using it to crush through some workflows, without ambr
I'd be totally lost.
Thanks for all your hard work!
Happy hacking,
Eric
Using Anchor v0.5.5 (precompiled binary) on Ubuntu 20.04, and testing it against Ripgrep 11.0.2.
Doing
f=$(tempfile)
cat <<EOF > "$f"
> []
> Test
> EOF
ambs -r -- '^Test' "$f"
ambs -r -- 'Test$' "$f"
outputs nothing, while
rg -s --no-heading --with-filename --no-line-number -- '^Test' "$f"
rg -s --no-heading --with-filename --no-line-number -- 'Test$' "$f"
outputs
/tmp/fileyO3IXf:Test
/tmp/fileyO3IXf:Test
Amber gives a lot of option to ignore things for different use cases which is great.
However it also comes with cost that there is a high chance that amber will run differently on different environments. And that could become hard to debug what things are being ignored and why.
In my use case is that running amber on Github Actions and somehow the target files being ignored and I just can't find why and the nature of Github Actions makes it hard to debug. Which is not a scope for Amber of course but I think having verbose option to see what amber is processing and skipping or ignoring and why would be awesome nonetheless.
When I run ambs
in one of my folders, it freezes on a file but I can't tell which one because there is no --verbose
(or --debug
) flag that makes amber
more chatty.
I'm calling amber from a batch script, it executes amber.exe tens of times in order. Some of them will randomly fail.
The script:
:: Replace #1/#2/#3
chcp 65001
echo "%1"
ambr.exe --no-interactive --regex "!\[\]\(https://dictionary\.goo\.ne\.jp/img/daijisen/gaiji/02539\.gif\)" "![[.1.gif]]" %1
ambr.exe --no-interactive --regex "!\[\]\(https://dictionary\.goo\.ne\.jp/img/daijisen/gaiji/02540\.gif\)" "![[.2.gif]]" %1
ambr.exe --no-interactive --regex "!\[\]\(https://dictionary\.goo\.ne\.jp/img/daijisen/gaiji/02541\.gif\)" "![[.3.gif]]" %1
ambr.exe --no-interactive --regex "!\[\]\(https://dictionary\.goo\.ne\.jp/img/daijisen/gaiji/02542\.gif\)" "![[.4.gif]]" %1
ambr.exe --no-interactive --regex "!\[\]\(https://dictionary\.goo\.ne\.jp/img/daijisen/gaiji/02543\.gif\)" "![[.5.gif]]" %1
ambr.exe --no-interactive --regex "!\[\]\(https://dictionary\.goo\.ne\.jp/img/daijisen/gaiji/02544\.gif\)" "![[.6.gif]]" %1
::Extract title
ambr.exe --no-interactive --regex "^# .+ goo国語辞書\n\n\n(.+)\n\nの解説" "# $1" %1
::Compress all second level nodes
ambr.exe --no-interactive --regex " (\d+\.) (.+)(?:\n) " " $1 $2" %1
ambr.exe --no-interactive --regex " \n 1." " 1." %1
::Replace all first and only sub example sentence/reference
ambr.exe --regex "^ 1. 「" " >「"" %1
::類語、関連語、下接語
ambr.exe --no-interactive --regex "^類語" "#### 類語" %1
ambr.exe --no-interactive --regex "^関連語" "#### 関連語" %1
ambr.exe --no-interactive --regex "^下接語" "#### 下接語" %1
::Correct first level numbered list bullets
ambr.exe --no-interactive --regex "^1\. \*\*1\*\*\s?" "1. " %1
ambr.exe --no-interactive --regex "^1\. \*\*2\*\*\s?" "2. " %1
ambr.exe --no-interactive --regex "^1\. \*\*3\*\*\s?" "3. " %1
ambr.exe --no-interactive --regex "^1\. \*\*4\*\*\s?" "4. " %1
ambr.exe --no-interactive --regex "^1\. \*\*5\*\*\s?" "5. " %1
ambr.exe --no-interactive --regex "^1\. \*\*6\*\*\s?" "6. " %1
ambr.exe --no-interactive --regex "^1\. \*\*7\*\*\s?" "7. " %1
ambr.exe --no-interactive --regex "^1\. \*\*8\*\*\s?" "8. " %1
ambr.exe --no-interactive --regex "^1\. \*\*9\*\*\s?" "9. " %1
ambr.exe --no-interactive --regex "^1\. \*\*10\*\*\s?" "10. " %1
ambr.exe --no-interactive --regex "^1\. \*\*11\*\*\s?" "11. " %1
ambr.exe --no-interactive --regex "^1\. \*\*12\*\*\s?" "12. " %1
ambr.exe --no-interactive --regex "^1\. \*\*13\*\*\s?" "13. " %1
ambr.exe --no-interactive --regex "^1\. \*\*14\*\*\s?" "14. " %1
ambr.exe --no-interactive --regex "^1\. \*\*15\*\*\s?" "15. " %1
ambr.exe --no-interactive --regex "^1\. \*\*16\*\*\s?" "16. " %1
ambr.exe --no-interactive --regex "^1\. \*\*17\*\*\s?" "17. " %1
ambr.exe --no-interactive --regex "^1\. \*\*18\*\*\s?" "18. " %1
ambr.exe --no-interactive --regex "^1\. \*\*19\*\*\s?" "19. " %1
ambr.exe --no-interactive --regex "^1\. \*\*20\*\*\s?" "20. " %1
ambr.exe --no-interactive --regex "^1\. \*\*21\*\*\s?" "21. " %1
ambr.exe --no-interactive --regex "^1\. \*\*22\*\*\s?" "22. " %1
ambr.exe --no-interactive --regex "^1\. \*\*23\*\*\s?" "23. " %1
ambr.exe --no-interactive --regex "^1\. \*\*24\*\*\s?" "24. " %1
ambr.exe --no-interactive --regex "^1\. \*\*25\*\*\s?" "25. " %1
ambr.exe --no-interactive --regex "^1\. \*\*26\*\*\s?" "26. " %1
ambr.exe --no-interactive --regex "^1\. \*\*27\*\*\s?" "27. " %1
ambr.exe --no-interactive --regex "^1\. \*\*28\*\*\s?" "28. " %1
ambr.exe --no-interactive --regex "^1\. \*\*29\*\*\s?" "29. " %1
ambr.exe --no-interactive --regex "^1\. \*\*30\*\*\s?" "30. " %1
The random fails looks like this:
>ambr.exe --no-interactive --regex "^1\. \*\*4\*\*\s?" "4. " ../aaa.md
Error: permission denied @ "../aaa.md" <<<<<
Found .gitignore at the parent directory: ".."
>ambr.exe --no-interactive --regex "^1\. \*\*5\*\*\s?" "5. " ../aaa.md
Found .gitignore at the parent directory: ".."
>ambr.exe --no-interactive --regex "^1\. \*\*6\*\*\s?" "6. " ../aaa.md
Found .gitignore at the parent directory: ".."
>ambr.exe --no-interactive --regex "^1\. \*\*7\*\*\s?" "7. " ../aaa.md
Found .gitignore at the parent directory: ".."
>ambr.exe --no-interactive --regex "^1\. \*\*8\*\*\s?" "8. " ../aaa.md
Error: permission denied @ "../aaa.md" <<<<<
Found .gitignore at the parent directory: ".."
>ambr.exe --no-interactive --regex "^1\. \*\*9\*\*\s?" "9. " ../aaa.md
Found .gitignore at the parent directory: ".."
!
support**
support$ make
...
Compiling amber v0.5.10-pre (/git/amber)
warning: unnecessary parentheses around match arm expression
--> src/matcher.rs:592:45
|
592 | (0x00..=0x7f, _, _, _, _, _) => (1), // ASCII
| ^ ^
|
= note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
|
592 - (0x00..=0x7f, _, _, _, _, _) => (1), // ASCII
592 + (0x00..=0x7f, _, _, _, _, _) => 1, // ASCII
|
warning: unnecessary parentheses around match arm expression
--> src/matcher.rs:593:55
|
593 | (0xc2..=0xdf, 0x80..=0xbf, _, _, _, _) => (2), // UTF-8
| ^ ^
|
help: remove these parentheses
|
593 - (0xc2..=0xdf, 0x80..=0xbf, _, _, _, _) => (2), // UTF-8
593 + (0xc2..=0xdf, 0x80..=0xbf, _, _, _, _) => 2, // UTF-8
|
warning: unnecessary parentheses around match arm expression
--> src/matcher.rs:594:65
|
594 | (0xe0..=0xef, 0x80..=0xbf, 0x80..=0xbf, _, _, _) => (3), // UTF-8
| ^ ^
|
help: remove these parentheses
|
594 - (0xe0..=0xef, 0x80..=0xbf, 0x80..=0xbf, _, _, _) => (3), // UTF-8
594 + (0xe0..=0xef, 0x80..=0xbf, 0x80..=0xbf, _, _, _) => 3, // UTF-8
|
warning: unnecessary parentheses around match arm expression
--> src/matcher.rs:595:75
|
595 | (0xf0..=0xf7, 0x80..=0xbf, 0x80..=0xbf, 0x80..=0xbf, _, _) => (4), // UTF-8
| ^ ^
|
help: remove these parentheses
|
595 - (0xf0..=0xf7, 0x80..=0xbf, 0x80..=0xbf, 0x80..=0xbf, _, _) => (4), // UTF-8
595 + (0xf0..=0xf7, 0x80..=0xbf, 0x80..=0xbf, 0x80..=0xbf, _, _) => 4, // UTF-8
|
warning: unnecessary parentheses around match arm expression
--> src/matcher.rs:596:85
|
596 | (0xf8..=0xfb, 0x80..=0xbf, 0x80..=0xbf, 0x80..=0xbf, 0x80..=0xbf, _) => (5), // UTF-8
| ^ ^
|
help: remove these parentheses
warning: unnecessary parentheses around match arm expression
--> /usr/home/yonas/git/make-cd/files/amber/src/matcher.rs:602:55
|
602 | (0x81..=0x9f, 0x80..=0xfc, _, _, _, _) => (2), // ShiftJIS
| ^ ^
|
help: remove these parentheses
|
602 - (0x81..=0x9f, 0x80..=0xfc, _, _, _, _) => (2), // ShiftJIS
602 + (0x81..=0x9f, 0x80..=0xfc, _, _, _, _) => 2, // ShiftJIS
|
warning: unnecessary parentheses around match arm expression
--> /usr/home/yonas/git/make-cd/files/amber/src/matcher.rs:603:55
|
603 | (0xe0..=0xef, 0x40..=0x7e, _, _, _, _) => (2), // ShiftJIS
| ^ ^
|
help: remove these parentheses
|
603 - (0xe0..=0xef, 0x40..=0x7e, _, _, _, _) => (2), // ShiftJIS
603 + (0xe0..=0xef, 0x40..=0x7e, _, _, _, _) => 2, // ShiftJIS
|
warning: unnecessary parentheses around match arm expression
--> /usr/home/yonas/git/make-cd/files/amber/src/matcher.rs:604:55
|
604 | (0xe0..=0xef, 0x80..=0xfc, _, _, _, _) => (2), // ShiftJIS
| ^ ^
|
help: remove these parentheses
|
604 - (0xe0..=0xef, 0x80..=0xfc, _, _, _, _) => (2), // ShiftJIS
604 + (0xe0..=0xef, 0x80..=0xfc, _, _, _, _) => 2, // ShiftJIS
|
warning: unnecessary parentheses around match arm expression
--> /usr/home/yonas/git/make-cd/files/amber/src/matcher.rs:605:18
|
605 | _ => (1), // Unknown
| ^ ^
|
help: remove these parentheses
|
605 - _ => (1), // Unknown
605 + _ => 1, // Unknown
|
warning: 14 warnings emitted
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
Is it possible to add amber to crates.io? It would be awesome to be able to install amber with cargo install amber
.
Thank you!
Suggestion: Enter should equal [y]
Thanks for the great tool!
When running either ambs
or ambr
specifying a path, it shows the fully qualified path.
abmr createShipment cs js/test
:
ambs createShipment js/tests
:
The directory I'm in when I ran the both commands was /Users/jaredramirez/dev/github.com/replenysh/replenysh-backend/
. It would save a lot of space and make the resulting search/replace be easier to interpret if ambs
/ambr
would only show ./js/tests/lib/_.js
when the specified path is in the current directory
I have a lot of things to template, so I use Amber in a script. Every time, Amber wants to replace the values found in that script which is currently telling amber to replace those values, so I have to be very careful not to ruin my script!
It'd be create that if amber could detect if, for instance, it is being called by /foo/bar/create_template.sh
then /foo/bar/create_template.sh
would be omitted from the list of files to be replaced.
Related to #47
Sorry if I missed this in the docs...
Is it possible to use a regex capture with ambr
?
For example, I want to do something like:
ambr --regex 'This is your (.*)' 'This is my \1'
I've tried '\1', '$1', as well as named captures, but those don't work.
Hi, on Windows Server 2022 showns a new windows with message "System Error"
Is there something about Windows Server 2022 to allow executing amber?
thanks,
Alex O.
Suggestion: -y flag to replace all without requiring any user input
I often use ambr for multiple passes of mass replacements, and it would be useful to have such a flag.
I want to run it from a justfile completely non-interactively (as part of a post-build step), how can I do that by passing a flag?
sed -n 5p path
How to do this in Amber?
This lets me pick just one line, in this case the fifth.
How to search a phrase?
ex:
grep -rnw -e 'text text'
How to specify the number of surrounding lines to show as context with ambr?
For making better replacing decisions.
EDIT:
It doesn't seem to have that option, at least according to -h
.
I suggest adding this option with -c <N>
/ --context <N>
It would also be useful for ambs
.
Suggestion: If the number is specified with a plus (+
) sign in front, only show N
following lines, none behind.
The line matched repeatedly is duplicated.
If we have a symlink, e.g.
1. A/a.txt
2. A-symlink/a.txt
then ambr replaces 1 and then wrongly replaces 2.
ambr 'nazel_package()' 'package(default_visibility = ["//visibility:public"])'
Replace keyword? [Y]es/[n]o/[a]ll/[q]uit: y
./A/a.txt: nazel_package()
-> package(default_visibility = ["//visibility:public"])
Replace keyword? [Y]es/[n]o/[a]ll/[q]uit: y
./A-symlink/a.txt: package(default_visibility = ["//visibility:public"])
-> package(default_visibility = ["//visibility:public"])_visibility = ["//visibility:public"])
When I use \n
in the replacement string, it doesn't work:
$ ambr -r "(?m)Vec3A as Vec3,\n" "Vec3,\n"
./spheres/src/lib.rs: pub resolution: Vec3A as Vec3,
pub time: f32,
-> pub resolution: Vec3,\n pub time: f32,
Replace keyword? [Y]es/[n]o/[a]ll/[q]uit: q
First of all I'd like to thank amber's author and contributors for this extremely helpful tool.
Second, I'd like to request that amber is published on Arch Linux's AUR.
I am a newbie regarding packaging, but I'm willing to work on it. I attach a prototype version of PKGBUILD, inspired by the one from the ripgrep-git
's package.
One of the issues that must be solved is the package naming, since a package named amber already exists.
Is there a shorthand for --regex
? If not, please add one :)
It looks like that amber
is the thing that "ambs", but what is the meaning of "amb" ?
Use case:
Sometimes I want to do an ambitious search or search/replace but I get a bunch of junk files I don't want to touch, like a CHANGELOG.md or a package-lock.json.
It would be nice to add an argument to ambs/ambr to ignore these files, e.g.
ambs --ignore-file '*.md' --ignore-file '*-lock.json' searchString
and
ambr --ignore-file '*-lock.json' fromString toString
The current workarounds I've been using are grep -v and trying to manually select 'no' on the replace query for the files I don't want to replace text inside. I can assure you, this is a very error prone process 😅
In ambr, when stepping through the matches, it shows Replace keyword? [Y]es/[n]o/[a]ll/[q]uit:
. To me, the capitalized Y
means that if I press enter, it will mean the same as Y
. But when I press enter, nothing happens, it just shows the same prompt again!
When replacing, the replaced lines have wrong line ending \r\n when the file uses line ending \n, on Windows when running in cmd.exe.
In msys it doesn't react to entering y
. Instead, I have to Ctrl-C and then it tries to execute y
on the shell.
Please allow using multiline regex, e.g. with (?m)
like the regex
crate or with --multiline
(or -U
) like ripgrep.
1. 「ことの葉は強 (こは) く見ゆれどすまひ草露には―・つるものにざりける」〈[源順集](https://dictionary.goo.ne.jp/word/person/%E6%BA%90%E9%A0%86/#jn-212920)〉
^ 1. 「(.+)\n(?! 2.)
expected to work but failed to match, does amber support Negative Look Ahead?^ 1. 「(.+)\n
matching works but replacing does not, it failed to capture. >「$1
replacement result:
Expected:
1. 「ことの葉は強 (こは) く見ゆれどすまひ草露には―・つるものにざりける」〈[源順集](https://dictionary.goo.ne.jp/word/person/%E6%BA%90%E9%A0%86/#jn-212920)〉
Returned:> 1. 「
\n
in replacement string.Using Anchor v0.5.5 (precompiled binary) on Ubuntu 20.04.
Doing
echo Test > f
ambs -r -- 'Test' f
results in
thread 'finder' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', src/pipeline_finder.rs:133:42
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
The behaviour is the same with ambr
.
Invoking both programs with ./f
instead of f
works fine.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.