Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to alias a sequence of tasks?

Tags:

I have custom tasks in my SBT (0.12.2) project. Let's call them a, b and c. So when I'm in the interactive mode of SBT I can just type a and the task associated with a is executed. I also can type ;a;b;c and the three tasks are executed in sequence; the same way something like ;clean;compile would do. What I also can do from the interactive shell is create an alias to run them all: alias all=;a;b;c. Now when I type all the tasks are executed in an obvious manner. What I'm trying to achieve is creating this alias inside of the SBT configuration for my project.

This section of SBT documentation deals with tasks, but all I could achieve was something like this:

lazy val a = TaskKey[Unit]("a", "does a") lazy val b = TaskKey[Unit]("b", "does b") lazy val c = TaskKey[Unit]("c", "does c") lazy val all = TaskKey[Unit]("all", ";a;b;c")  lazy val taskSettings = Seq(     all <<= Seq(a,b,c).dependOn ) 

The problem I have with this approach is that the tasks are combined and thus their execution happens in parallel in contrast to sequential, which is what I'm trying to achieve. So how can I create an alias like alias all=;a;b;c inside of the SBT configuration file?

like image 539
agilesteel Avatar asked Apr 25 '13 08:04

agilesteel


People also ask

What is the alias command in Linux?

alias command instructs the shell to replace one string with another string while executing the commands. When we often have to use a single big command multiple times, in those cases, we create something called as alias for that command.

What is an alias terminal?

Aliases are nothing more than keyboard shortcuts or abbreviations, and although they're a bit limited, they're great for simple commands. Let's create a temporary alias in the command line for ls -al (list all files in long listing format in the current directory).


2 Answers

I've been looking for the same thing and found this request for an easy way of aliasing and the commit that provides one: addCommandAlias.

In my build.sbt I now have:

addCommandAlias("go", ";container:start;~copy-resources") 

As you might guess, writing go in the console will now run the longer command sequence for me.

like image 104
lime Avatar answered Nov 04 '22 10:11

lime


another way to achieve this is to define an alias in your .sbtrc file which will be in the root of your project directory.

alias all=;a;b;c 

you have an additional option of defining these .sbtrc file in your home directory in which case this alias will be available to all your projects.

like image 40
rogue-one Avatar answered Nov 04 '22 11:11

rogue-one