Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 99 lines (80 sloc) 2.459 kb
#! /usr/bin/env coffee
fs = require('fs')
util = require('util')
exec = require('child_process').exec
# log debug messages to file if enabled
debug = false
# print to stdout
print = (error, stdout, stderr) ->
util.print(stdout)
# get user home
getUserHome = () ->
if (process.platform is 'win32')
v = 'USERPROFILE'
else
v = 'HOME'
process.env[v]
# set up logging
if debug
logStream = fs.createWriteStream(getUserHome() + '/log/ctags.log', {'flags': 'a'})
log = (text) ->
logStream.write(text + "\n")
else
log = () ->
# shift iced and script name away
process.argv = process.argv[2..]
# log input vars
log(process.argv.join("___"))
# easytags adds -f switch and puts file name after that without a space ...
log('testing args for file switch')
for arg, i in process.argv
log('testing arg: "' + arg + '"' + /^-f.+/.test(arg))
if /^-f.+/.test(arg)
process.argv[i] = '-f'
process.argv.splice(i+1, 0, arg.slice(2))
log(process.argv.join("___"))
break
# get input files
inputFiles = []
foundJS = false
for i in [process.argv.length-1..0]
inputFile = process.argv[i]
log "testing for file name " + inputFile
if /(^-)/.test(inputFile) is true then break
# test for next switch
if i > 0 and process.argv[i-1] is '-f' then break
# all ok, add input file
inputFiles.push inputFile
if /.*\.js$/.test(inputFile) is true then foundJS = true
log 'found js files? ' + foundJS
# ctags call
if process.argv.indexOf("--language-force=javascript") < 0 and foundJS is false
log 'ctags call'
exec("/usr/bin/ctags " + process.argv.join(" "), print)
return
log 'jsctags call'
# command string
cmd = "jsctags "
# set output file to argument or standard file name 'tags'
outputFileIndex = process.argv.indexOf("-f")
if outputFileIndex >= 0
outputFile = process.argv[outputFileIndex+1]
else
outputFile = 'tags'
log 'outputFile: ' + outputFile
# append file or overwrite old one?
if process.argv.indexOf("-a") < 0
log 'write output to file'
cmd += "-f " + outputFile + " "
cmd += inputFiles.join(" ")
else
log 'append output to file'
cmd += "-f - "
cmd += inputFiles.join(" ") + " "
#wrong ... tag files says its unsorted
#if process.argv.indexOf("-s") >= 0
#cmd += "| sort "
cmd += " | tail -n +7 >> " + outputFile
# execute jsctags command
log 'command: ' + cmd
exec(cmd, print)
Jump to Line
Something went wrong with that request. Please try again.