Command Line Preview Running Application


#1

I want to run the menu command “Preview” --> “Preview Running Application” from the command line in a terminal. Fairly sure it is an easy command, just can’t figure out what it is. I know I can start the Apache2 server with this command

service apache2 start

Any suggestions?

If it can be done, what is the extra command to have the browser open in a new window and not the cloud9 workspace window.


#2

There is no command for this yet.
It is possible to add a preview command to c9 cli utility https://github.com/c9/core/blob/master/plugins/c9.cli.bridge/bridge_commands.js#L35 https://github.com/c9/core/blob/master/plugins/c9.cli.open/open.js#L25
It might be something like c9 preview [-n] [path] with optional path (previewing app if there is no path sent)
and -n flag for opening a new tab


#3

That is a bit more advanced than I was looking for, did not realize menu commands could not be accessed from the command line.

Oh well not a big deal.

If someone finds a way, drop a comment please.


#4

From the command line I can write a clickable url such as

echo “http://www.google.com

Anyone who knows the url for their workspace can simple write it in an echo in a bash file, but I want the bash file to be on github so a new user can make a clickable url. The problem is, that I will need variables for the workspace name and the userlogin.

I know that these variables work

echo $USER $PORT $IP $HOME $HOSTNAME

ubuntu 8080 0.0.0.0 /home/ubuntu userNane-workspaceName-randomNumber

.

.

.

Any idea of variables that can be used to make a user URL?

In the form

echo “http://workspaceName-UserName.c9users.io

I may have answered this myself. I think $HOSTNAME has all the information needed I just have to figure out how to parse it in a bash file.

Any easier suggestions?


#5

That was fast. Lucky google search.

gave me IFS=- read var1 var2 <<< ABCD-1234

so,this works

IFS=- read var1 var2 var3 var4<<< $HOSTNAME

echo "http://$var2-$var3-$var1.c9users.io"

#6

Dang it. the above is dependent on the number of dashes in the workspace name. So it now becomes much more confusing.

This works but only for up to 3 dashes in the workspace name, can someone figure out how to do it as a loop so it would work for any number of dashes in the workspace name

y="${HOSTNAME//[^-]}"
echo "$y"
echo "${#y}"
echo $HOSTNAME

if [ ${#y} = 4 ]; then
    IFS=- read var1 var2 var3 var4 var5 <<< $HOSTNAME
    echo "http://$var2-$var3-$var4-$var1.c9users.io"
fi


if [ ${#y} = 3 ]; then
    IFS=- read var1 var2 var3 var4 <<< $HOSTNAME
    echo "http://$var2-$var3-$var1.c9users.io"
fi

if [ ${#y} = 2 ]; then
    IFS=- read var1 var2 var3 <<< $HOSTNAME
    echo "http://$var2-$var1.c9users.io"
fi

#7

you can use $C9_HOSTNAME for this

c9 adds several other environment variable too all prefixed with C9_
typing echo $C9_<Tab> in terminal gives

$C9_EMAIL        $C9_FULLNAME     $C9_HOSTNAME     $C9_IP          
$C9_PID          $C9_PORT         $C9_PROJECT      $C9_SHARED      
$C9_SH_EXECUTED  $C9_UID          $C9_USER 

#8

But I had a lot of fun writing 16 lines of poorly made code that can be replaced with one well written line.

echo "http://$C9_HOSTNAME"

Thanks @harutyun I think I will ask for you by name next time.


#9

Any suggestions how to view $C9_HOSTNAME from within node.js

console.log(‘http://$C9_HOSTNAME’);

does not replace the variable. Other ideas do also not seem to work

console.log(‘http://’+$C9_HOSTNAME);


#10

use process.env.C9_HOSTNAME


#11

Sweet. This line works great

console.log('http://'+process.env.C9_HOSTNAME);