S
S
Sergey Goryachev2016-12-13 11:17:15
linux
Sergey Goryachev, 2016-12-13 11:17:15

How to create your command in the console?

Want Want want!
I want to run local sites with my own team.
I have Galp, now the command is used:

cd public_html/sitename.loc/ && atom . && gulp watch

And I want it differently, for example:
siteloc sitename start
So that both Atom and Galp are launched at the same time.
This is generally in which direction to dig?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
S
Sergei E., 2016-12-13
@webirus

It's strange that no one suggested the easiest and, in my opinion, the most suitable way for this case - create a function in .bashrc
paste these lines at the end of the ~/.bashrc file

function siteloc() {
  # выйти если нет аргумента
  [ -n "$1" ] || return 1
  cd "$HOME/public_html/$1.loc"
  atom .
  gulp watch
}

and run the command source ~/.bashrcfor the changes to take effect.
After that, you can execute this set of commands with the line: siteloc sitename
In the future, you can improve this function, for example, add a check to see if the directory exists "$HOME/public_html/$1.loc".

I
Igor, 2016-12-13
@DMGarikk

Dig towards shell scripts

M
Max, 2016-12-13
@MaxDukov

look in /etc/init.d - there are scripts that start services. You want to make an analog.

D
Dmitry, 2016-12-13
@plin2s

If a single command without parameters like "siteloc-sitename-start" works, then google towards bash alias. If you need a service with parameters, then you need to do an init / systemd script.

C
CityCat4, 2016-12-13
@CityCat4

Towards the Bourne Shell. Write a scripter that will be allowed to process the start/stop parameters, name it siteloc - no one will interfere. In general, Bourne Shell is real elven magic, it works wonders :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question