"ctags: Unknown option: --output-format" error - ctags

On macOS, getting the error while running this command:
ctags -R --output-format=json --languages=ruby --exclude=.git --exclude=log . $(bundle list --paths) -f .tags
per advice here: https://www.boost.co.nz/blog/2018/01/improving-ruby-rails-debugging-ctags
It appears to be a valid command option: https://docs.ctags.io/en/latest/output-format.html
So I'm not sure why I'm getting an error.
UPDATE:
OK, that blog article has ctags installed from HEAD formula. So I installed that version but now I get a different error:
ctags: unknown output format name supplied for "output-format=json"

I followed the same article and got the same error. The problem is the suggested command:
brew install --HEAD universal-ctags/universal-ctags/universal-ctags
This doesn't build universal-ctags with libjansson and as Masatake YAMATO suggested, libjansson is needed to use --output-format=json.
Try installing universal-ctags with the --with-jansson flag:
brew install --HEAD --with-jansson universal-ctags/universal-ctags/universal-ctags
Also, to avoid the ctags: -f option may not follow a file name error, move -f .tags before . $(bundle list --paths):
ctags -R --output-format=json --languages=ruby --exclude=.git --exclude=log -f .tags . $(bundle list --paths)

You can use json output only when you built the ctags executable with libjansson library.
If you built the ctags executable with libjansson, you will see "json" in --list-features output like:
$ universal-ctags --list-features
#NAME DESCRIPTION
iconv can convert input/output encodings
interactive accepts source code from stdin
json supports json format output
...
If you don't find "json", you must rebuild the ctags executable with libjansson library.
If you find "json", but the option, --output-format=json, doesn't work, it will be a bug. I recommend you to report it to https://github.com/universal-ctags/ctags/issues though fixing it is not promised.

Related

I am getting SHA256 checksum mismatch error with brew install "formula"

I am using MAC OS and for the first time I am trying to create my own package using brew package manager.
I have placed a simple helloworld shell script inside a tar file and pushed it to my github repository.
Please refer to the link https://github.com/shahritesh16/tutorial1.
I have written simple formula which is shown below:
class Script < Formula
desc "Shell script for hello world"
homepage "https://github.com/shahritesh16/tutorial1"
url "https://github.com/shahritesh16/tutorial1/blob/master/brewtest-0.1.tar.gz"
sha256 "30f1cc5cabe3b988d567e561713eae01840c4c0781daf7e2709c9c6b79dba4b1"
def install
echo Welcome
end
end
I have created the tar.gz file using these commands:
tar -cvf brewtest-0.1.tar.gz brewdir
I have calculated the sha256 value using shasum -a 256 /location/brewtest-0.1.tar.gz and added the value in ruby script script.rb.
Up on executing the command, brew install script.rb I am getting ChecksumMismactherror.
Below is the output:
==> Downloading https://github.com/shahritesh16/tutorial1/blob/master/brewtest-0.1.tar.gz
######################################################################## 100.0%
Error: An exception occurred within a child process:
ChecksumMismatchError: SHA256 mismatch
Expected: 30f1cc5cabe3b988d567e561713eae01840c4c0781daf7e2709c9c6b79dba4b1
Actual: 39524ab2e5177ddbb9d9cfac7c535ea5c6f290e8ecbbec6b67de189ba5435c6e
Archive: /Users/xyzUser/Library/Caches/Homebrew/downloads/e0b1da9a7a7fff80ece6531f3f5660d6a8bf4e1fba006910543da58e44330f5d--brewtest-0.1.tar.gz
To retry an incomplete download, remove the file above.
I am not sure why I am getting this error as I am using correct SHA256 value in script.rb as per shasum -a 256 filelocation command. Also Why it is comparing sha256 value from script.rb with the one that is downloaded in /Users/xyzUser/Library/Caches/Homebrew/downloads.
The checksum mismatches is due to an error in the URL. https://github.com/shahritesh16/tutorial1/blob/master/brewtest-0.1.tar.gz points to the HTML-rendered version of the file. What you should have used is the URL you get when clicking on the "Raw" button on this file:
https://github.com/shahritesh16/tutorial1/raw/master/brewtest-0.1.tar.gz
Note the "raw" part in that URL.
Also, the formula’s name should match its filename: use Brewtest instead of Script:
class Brewtest < Formula
desc "Shell script for hello world"
homepage "https://github.com/shahritesh16/tutorial1"
url "https://github.com/shahritesh16/tutorial1/raw/master/brewtest-0.1.tar.gz"
sha256 "30f1cc5cabe3b988d567e561713eae01840c4c0781daf7e2709c9c6b79dba4b1"
def install
puts "Hello"
end
end

Ruby gem tab completion on zsh produces "doubled rest argument definition" error?

When I hit gem push <tab>, it displays this error (regardless of whether the directory contains any .gem files):
_arguments:comparguments:325: doubled rest argument definition: *:gem:_files -g "*.gem(-.)"
_arguments:comparguments:325: doubled rest argument definition: *:gem:_files -g "*.gem(-.)"
_arguments:comparguments:325: doubled rest argument definition: *:gem:_files -g "*.gem(-.)"
I have no idea how to fix this and Google is no help. My fpath:
> echo $fpath
/Users/robenkleene/.zsh/completion
/usr/local/share/zsh/site-functions
/usr/local/Cellar/zsh/5.7/share/zsh/functions
I've tried uninstalling and re-installed Ruby via homebrew because the above "Cellar" path contains a _gem file that I believe defines this completion function, but that didn't work.
Any other ideas? Thanks!
(Also, if anyone has any suggestions of where I might file a bug report for this that would also be helpful, thanks again!)
I hacked together my own terrible solution to this but it's better than nothing.
I copied the _gem file from /usr/local/Cellar/zsh/5.7/share/zsh/functions to /Users/robenkleene/.zsh/completion and then modified the offending line (note that this only works because I have fpath=(~/.zsh/completion $fpath) in my zshrc):
- args+=( '*:gem:_files -g "*.gem(-.)"' )
+ args=( '*:gem:_files -g "*.gem(-.)"' )
So I removed the +. This seems to work, but I'd love a more elegant solution and/or any information about why (based on my Google search), I seem to be the only person experiencing this.
I'm on macOS 10.15.6 running the default zsh 5.7.1. In the default zsh gem completion I found that push is being included in a list of commands which take a remote gem name — and it shouldn't be, it only takes the path to the gem file:
$ gem push --help
Usage: gem push GEM [options]
I applied the following patch to a copy of the file higher in $fpath and it now works for me:
--- /usr/share/zsh/5.7.1/functions/_gem
+++ ~/.zsh/completion.d/_gem
## -56,7 +56,7 ##
check|cleanup|contents|dependency|list|open|pristine|rdoc|uninstall|unpack|update)
args+=( '(--all --skip)*:installed gem:->gems-local' )
;|
- fetch|install|lock|owner|push|search|yank)
+ fetch|install|lock|owner|search|yank)
args+=( '*:gem:->gems-remote' )
;|
cleanup|uninstall)
I'm not sure where to contribute this patch. 😅

Generate ctags for Ruby and Javascript

Currently I'm using this command to generate ctags:
ctags -R --languages=ruby,javascript --exclude=.git --exclude=log . $(bundle list --paths)
This works for Ruby, but not for the JavaScript. How can I fix that, so that JavaScript code will be in ctags too?
Adding --tag-relative and --sort=yes fixed the problem.
ctags --tag-relative -R --sort=yes --languages=ruby,javascript --exclude=.git --exclude=log . $(bundle list --paths)

Exuberant Ctags can't work fine on OSX

I want use Ctags for Lua.
Ctags doesn't support Lua, so I found a command:
ctags --langdef=MYLUA --langmap=MYLUA:.lua --regex-MYLUA="/^.*\s*function\s*(\w+):(\w+).*$/\2/f/" --regex-MYLUA="/^\s*(\w+)\s*=\s*[0-9]+.*$/\1/e/" --regex-MYLUA="/^.*\s*function\s*(\w+)\.(\w+).*$/\2/f/" --regex-MYLUA="/^.*\s*function\s*(\w+)\s*\(.*$/\1/f/" --regex-MYLUA="/^\s*(\w+)\s*=\s*\{.*$/\1/e/" --regex-MYLUA="/^\s*module\s+\"(\w+)\".*$/\1/m,module/" --regex-MYLUA="/^\s*module\s+\"[a-zA-Z0-9._]+\.(\w+)\".*$/\1/m,module/" --languages=MYLUA --excmd=number -R .
It's too long, or you can see a shorter sample only for lua functions.
ctags --langdef=MYLUA --langmap=MYLUA:.lua --regex-MYLUA="/^.*\s*function\s*(\w+)\s*\(.*$/\1/f/" --languages=MYLUA --excmd=number -R .
Both of the two works fine on Windows.
On OSX, there was no error, but the tags file is empty.
PS:I used Exuberant Ctags v5.8, not default ctags on OSX.
Here's a test Lua code for ctags.
function f1()
end
function c.f2()
end
function c:f3()
end
The exuberant ctags version that you can find at https://github.com/fishman/ctags appears to have native lua support. Have you tried that instead?
Finally, i fixed it.
'\w' can't use in this regex('\w' isn't OK, too), i don't know why. I use '[^\s:>]' instead of '\w'.
'\1' or '\2' must escape to '\\1' or '\\2', but '\s' is OK. Don't know why, too.
Now, the command change to
ctags --langdef=MYLUA --langmap=MYLUA:.lua --regex-MYLUA="/^.*\s*function\s*([^\s:.]+):([^\s:.]+).*$/\\2/f/" --regex-MYLUA="/^\s*([^\s:.]+)\s*=\s*[0-9]+.*$/\\1/e/" --regex-MYLUA="/^.*\s*function\s*([^\s:.]+)\.([^\s:.]+).*$/\\2/f/" --regex-MYLUA="/^.*\s*function\s*([^\s:.]+)\s*\(.*$/\\1/f/" --regex-MYLUA="/^\s*([^\s:.]+)\s*=\s*\{.*$/\\1/e/" --regex-MYLUA="/^\s*module\s+\"([^\s:.]+)\".*$/\\1/m,module/" --regex-MYLUA="/^\s*module\s+\"[a-zA-Z0-9._]+\.([^\s:.]+)\".*$/\\1/m,module/" --languages=MYLUA --excmd=number -R .
and this is OK.

How can I determine what the current stable version of Ruby is?

I want to write a Ruby method that does two things:
Determine what the current stable version of Ruby is. My first thought is to get the response from https://www.ruby-lang.org/en/downloads/ and use RegEx to isolate the phrase The current stable version is [x]. Is there is an API I'm not aware of?
Get the URL to download the .tar.gz of that release. For this I was thinking the same thing, get it from the output of the site URL.
I'm looking for advice about the best way to go about it, or direction if there's something in place I might use to determine my desired results.
Ruby code to fetch the download page, then parse the current version and the link URL:
html = Net::HTTP.get(URI("https://www.ruby-lang.org/en/downloads/"))
vers = html[/http.*ruby-(.*).tar.gz/,1]
link = html[/http.*ruby-.*.tar.gz/]
GitHub code: ruby-stable-version.rb
Shell code:
ruby-stable-version
If you are using rbenv you can use ruby-build to get a list of ruby versions and then grep against that.
ruby-build --definitions | tail -r | grep -x -G -m 1 '[0-9]\.[0-9].[0-9]\-*[p0-9*]*'
You can then use that within your code like so:
version = `ruby-build --definitions | tail -r | grep -x -G -m 1 '[0-9]\.[0-9].[0-9]\-*[p0-9*]*'`.strip
You can then use this value to get the download URL.
url = "http://cache.ruby-lang.org/pub/ruby/#{version[0..2]}/ruby-#{version}.tar.gz"
And then download the file:
require 'open-uri'
open("ruby-#{version}.tar.gz", 'wb') do |file|
file << open(url).read
end
Learn more about rbenv here and ruby-build here.
Another possibility would be to use the Ruby source repository. Check version.h in every branch, filter by RUBY_PATCHLEVEL > -1 (-1 is used for -dev versions), sort by RUBY_VERSION and take the latest one.
You can use:
Ruby's built-in OpenURI, and Nokogiri, to read a page, parse it, search for certain tags, extract a parameter such as a "src" or "href".
OpenURI to read the URL, or curl or wget at the command-line to retrieve the file.
Nokogiri's tutorials including showing how to use OpenURI to retrieve the page and hand it off to Nokogiri.
OpenURI's docs show how to "open" URLs and retrieve their content using read. Once you've done that, the data will be easy to save to disk using something like this for text files:
File.write('some_file', open('http://www.example.com/').read)
or for binary:
File.open('some_file', 'wb') { |fo| fo.write(open('http://www.example.com/').read) }
There are examples of using both Nokogiri and OpenURI for this all over Stack Overflow.

Resources