Skip to content

Commit

Permalink
Add -s "save" option
Browse files Browse the repository at this point in the history
Sets the output file to the path of the input file
  • Loading branch information
Tony Crisci committed Apr 27, 2014
1 parent 4b53115 commit 720cdc8
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/cli.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ program
.usage('<theme> [options]')
.option('-c, --config <file>', 'The config file the theme should be applied to. Defaults to the default i3 location.')
.option('-o, --output <file>', 'Applies the theme, attempts to validate the result, and writes it to <file>. Prints to STDOUT if no output file is given.')
.option('-s, --save', 'Sets the output file to the path of the input file')
.option('-r, --reload', 'Apply the theme by reloading your config with i3-msg (restart may be required to apply bar colors)')
.option('-l, --list-all', 'Prints a list of all available themes.')
.parse(process.argv)
Expand Down Expand Up @@ -84,7 +85,15 @@ configPath = switch
config = mkConfig theme, sh.cat(configPath)

# no output file specified. echo result to stdout and we are done.
unless program.output
outputPath = switch
when program.output
program.output
when program.save
configPath
else
null

unless outputPath
sh.echo config
sh.exec('i3-msg reload') if program.reload
process.exit 0
Expand Down Expand Up @@ -112,6 +121,7 @@ if tmpdir and not process.env.I3STYLETEST
sh.cp(configPath, tmpPath)

# finally write the file to the specified location
fs.writeFile program.output, config, (err) ->
fs.writeFile outputPath, config, (err) ->
exitWithError "Could not write to file: #{program.output}\n\n#{err}" if err
sh.echo "Applied #{program.args[0]} theme to #{outputPath}"
sh.exec('i3-msg reload') if program.reload

0 comments on commit 720cdc8

Please sign in to comment.