1

The below program (when-changed) gives the filename %f which can be used in the command. How can I get only the filename without file extension from this %f ?

This is the command that I want to use:

when-changed *.scss -c sassc %f f%-min.css

It saves a filename like: layout.scss-min.css What I need is only layout-min.css, if possible.

haheute
  • 2,129
  • 3
  • 32
  • 49
  • 1
    As seen in [Extract filename and extension in bash](http://stackoverflow.com/a/965072/1983854), use `filename="${filename%.*}"`. – fedorqui Jun 19 '14 at 11:31
  • 1
    `echo layout.scss-min.css | awk '{print substr($0,0,index($0,".")-1) substr($0,index($0,"-"))}'` –  Jun 19 '14 at 11:46

2 Answers2

2

Create a little shell script that calls sassc for you, instead of calling it directly:

#!/bin/bash
filename=$1
outfile="${filename%.*}"  # Do your filename replacement here
sassc "$filename" "$outfile"

Then call:

 when-changed *.scss -c ./myscript.sh %f
Sjoerd
  • 74,049
  • 16
  • 131
  • 175
0

You can not do this on the command line. The filename is not really put in the %f variable on the command line. Instead, you pass %f to when-changed and when-changed itself replaces it with the filename.

Change the source of when-changed to do what you want. For example, change this part:

def run_command(self, file):
    os.system(self.command.replace('%f', file))

To this:

def run_command(self, file):
    command = self.command
    command = command.replace('%f', file)
    command = command.replace('%c', file.replace('.scss', ''))
    os.system(command)
Sjoerd
  • 74,049
  • 16
  • 131
  • 175