Is there a way to "grep" inside REPL?

Inside the REPL, for example, when I do methods(HomogenousMesh) from GeometryTypes.jl, I will get the following list of many signatures:

julia> methods(HomogenousMesh)
# 15 methods for type constructor:
[1] (::Type{HomogenousMesh})(vertices::Array{VertT,1}, faces::Array{FaceT,1}, normals::Array{NormalT,1}, texturecoordinates::Array{TexCoordT,1}, color::ColorT, attributes::AttribT, attribute_id::Array{AttribIDT,1}) where {VertT, FaceT, NormalT, TexCoordT, ColorT, AttribT, AttribIDT} in GeometryTypes at /home/hiro/.julia/packages/GeometryTypes/8vIFC/src/types.jl:169
[2] (::Type{HomogenousMesh})(vertices::AbstractArray{VertT,1}, faces::AbstractArray{FaceT,1}, normals::AbstractArray{NormalT,1}, texturecoordinates::AbstractArray{TexCoordT,1}, color::ColorT, attributes::AttribT, attribute_id::AbstractArray{AttribIDT,1}) where {VertT, FaceT, NormalT, TexCoordT, ColorT, AttribT, AttribIDT} in GeometryTypes at /home/hiro/.julia/packages/GeometryTypes/8vIFC/src/types.jl:187
[3] (::Type{M})(; kw_args...) where M<:HomogenousMesh in GeometryTypes at /home/hiro/.julia/packages/GeometryTypes/8vIFC/src/meshes.jl:105
[4] (meshtype::Type{T})(c::Union{HyperCube{3,T}, HyperRectangle{3,HT}}) where {T<:HomogenousMesh, HT} in GeometryTypes at /home/hiro/.julia/packages/GeometryTypes/8vIFC/src/primitives.jl:45
[5] (::Type{HM1})(primitive::HM2) where {HM1<:HomogenousMesh, HM2<:HomogenousMesh} in GeometryTypes at /home/hiro/.julia/packages/GeometryTypes/8vIFC/src/meshes.jl:60
[6] (::Type{M})(vertices::AbstractArray{Point{3,VT},1}, faces::AbstractArray{FT,1}) where {M<:HomogenousMesh, VT, FT<:Face} in GeometryTypes at /home/hiro/.julia/packages/GeometryTypes/8vIFC/src/meshes.jl:85
[7] (::Type{M})(attribs::Dict{Symbol,Any}) where M<:HomogenousMesh in GeometryTypes at /home/hiro/.julia/packages/GeometryTypes/8vIFC/src/meshes.jl:111
[8] (::Type{M})(mesh::AbstractMesh, attributes::Dict{Symbol,Any}) where M<:HomogenousMesh in GeometryTypes at /home/hiro/.julia/packages/GeometryTypes/8vIFC/src/meshes.jl:123
[9] (::Type{HM})(mesh::AbstractMesh, constattrib::ConstAttrib) where {HM<:HomogenousMesh, ConstAttrib} in GeometryTypes at /home/hiro/.julia/packages/GeometryTypes/8vIFC/src/meshes.jl:132
[10] (::Type{HM})(x::Tuple{P,ConstAttrib}) where {HM<:HomogenousMesh, ConstAttrib, P<:AbstractGeometry} in GeometryTypes at /home/hiro/.julia/packages/GeometryTypes/8vIFC/src/meshes.jl:152
[11] (meshtype::Type{T})(c::Pyramid) where T<:AbstractMesh in GeometryTypes at /home/hiro/.julia/packages/GeometryTypes/8vIFC/src/primitives.jl:3
[12] (::Type{T})(c::HyperSphere{2,T} where T) where T<:AbstractMesh in GeometryTypes at /home/hiro/.julia/packages/GeometryTypes/8vIFC/src/primitives.jl:29
[13] (::Type{T})(c::HyperSphere{2,T} where T, n) where T<:AbstractMesh in GeometryTypes at /home/hiro/.julia/packages/GeometryTypes/8vIFC/src/primitives.jl:29
[14] (meshtype::Type{T})(c::GeometryPrimitive, args...) where T<:AbstractMesh in GeometryTypes at /home/hiro/.julia/packages/GeometryTypes/8vIFC/src/primitives.jl:14
[15] (::Type{M})(points::AbstractArray{P,N} where N) where {M<:AbstractMesh, P<:Point} in GeometryTypes at /home/hiro/.julia/packages/GeometryTypes/8vIFC/src/polygons.jl:152

I want to do grep here, like

methods(HomogenousMesh) | grep Abstract

to extract all the lines which include the sequence Abstract. Is there a way to do this?

1 Like

Something like this?

julia> methods(!)
# 3 methods for generic function "!":
[1] !(::Missing) in Base at missing.jl:100
[2] !(x::Bool) in Base at bool.jl:33
[3] !(f::Function) in Base at operators.jl:896

julia> collect(eachmatch( r".*operators.*", sprint(show,methods(!)) ))
1-element Array{RegexMatch,1}:
 RegexMatch("[3] !(f::Function) in Base at operators.jl:896")
4 Likes

Check out my package NicePipes.jl, it does pretty much exactly that!

7 Likes