mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-11-11 11:11:50 -05:00
fix(ruby): preserve special characters in rfind filenames (#14173)
This commit is contained in:
@@ -14,7 +14,7 @@ plugins=(... ruby)
|
|||||||
| ------- | -------------------------------------- | ---------------------------------------------------- |
|
| ------- | -------------------------------------- | ---------------------------------------------------- |
|
||||||
| rb | `ruby` | The Ruby command |
|
| rb | `ruby` | The Ruby command |
|
||||||
| sgem | `sudo gem` | Run sudo gem on the system ruby, not the active ruby |
|
| sgem | `sudo gem` | Run sudo gem on the system ruby, not the active ruby |
|
||||||
| rfind | `find . -name "*.rb" \| xargs grep -n` | Find ruby file |
|
| rfind | `find . -name "*.rb" -print0 \| xargs -0 grep -n` | Find ruby file |
|
||||||
| rrun | `ruby -e` | Execute some code: E.g: `rrun "puts 'Hello world!'"` |
|
| rrun | `ruby -e` | Execute some code: E.g: `rrun "puts 'Hello world!'"` |
|
||||||
| rserver | `ruby -run -e httpd . -p 8080` | Start HTTP Webrick serving local directory/files |
|
| rserver | `ruby -run -e httpd . -p 8080` | Start HTTP Webrick serving local directory/files |
|
||||||
| gein | `gem install` | Install a gem into the local repository |
|
| gein | `gem install` | Install a gem into the local repository |
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
alias sgem='sudo gem'
|
alias sgem='sudo gem'
|
||||||
|
|
||||||
# Find ruby file
|
# Find ruby file
|
||||||
alias rfind='find . -name "*.rb" | xargs grep -n'
|
alias rfind='find . -name "*.rb" -print0 | xargs -0 grep -n'
|
||||||
|
|
||||||
# Shorthand Ruby
|
# Shorthand Ruby
|
||||||
alias rb="ruby"
|
alias rb="ruby"
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
|
||||||
|
emulate -LR zsh
|
||||||
|
|
||||||
|
source "${1:-${0:A:h:h}/ruby.plugin.zsh}"
|
||||||
|
|
||||||
|
test_dir=$(mktemp -d) || exit 1
|
||||||
|
trap 'command rm -rf -- "$test_dir"' EXIT
|
||||||
|
|
||||||
|
typeset -i failures=0 tests=0
|
||||||
|
typeset filename output
|
||||||
|
|
||||||
|
for filename in plain.rb 'file with spaces.rb' "single'quote.rb" 'double"quote.rb' $'line\nbreak.rb' 'unicode-ą.rb'; do
|
||||||
|
print -r -- 'needle' >| "$test_dir/$filename"
|
||||||
|
output=$(cd "$test_dir" && rfind needle 2> "$test_dir/stderr")
|
||||||
|
actual_status=$?
|
||||||
|
(( tests++ ))
|
||||||
|
|
||||||
|
if [[ $actual_status == 0 && $output == '1:needle' && ! -s "$test_dir/stderr" ]]; then
|
||||||
|
print -r -- "PASS: ${(qqq)filename}"
|
||||||
|
else
|
||||||
|
print -u2 -r -- "FAIL: ${(qqq)filename} (status $actual_status)"
|
||||||
|
print -u2 -r -- " stdout: ${(qqq)output}"
|
||||||
|
print -u2 -r -- " stderr: $(<"$test_dir/stderr")"
|
||||||
|
(( failures++ ))
|
||||||
|
fi
|
||||||
|
|
||||||
|
command rm -- "$test_dir/$filename"
|
||||||
|
done
|
||||||
|
|
||||||
|
print -r -- "$tests tests, $failures failures"
|
||||||
|
(( failures == 0 ))
|
||||||
Reference in New Issue
Block a user