Reputation:
I want to make a command like:
chrome "site.com"
which will make a google chrome window to pop up with the site instantly. Is there any way to achieve this?
Upvotes: 15
Views: 26002
Reputation: 1
#!/bin/bash
baseUrl='https://www.google.com/search?q='
query='windows bash start browser'
url="$baseUrl""$query"
start chrome "$url"
start firefox "$url"
start msedge "$url"
#Default browser
start "" "$url"
This works for me to open an URL in the default browser on Windows 11 in git bash (GNU bash, version 5.2.26)
Without the "", passing e.g. an URL containing spaces would open cmd.exe, with the URL as the window title. (Spaces are not allowed in an URL, but it works in Firefox, Edge and Chrome.)
If the first parameter has double quotes it uses that as the optional TITLE for the new window... give it an empty title
https://stackoverflow.com/a/154090
https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/start
Upvotes: 0
Reputation: 22731
Depending on your situation, a more cross-platform solution might be to use git web--browse
, which will attempt to open a url (or file) in a browser.
For example, this would open a link to github for opening a PR:
URL="${GIT_REPO}/compare/${CURRENT_BRANCH}?expand=1"
echo "opening $URL"
git web--browse $URL
There is also a --browser
option where you can target a specific browser.
See: https://git-scm.com/docs/git-web--browse
Upvotes: 2
Reputation: 730
start http://example.com
Opens the default browser with the URL.
Tested on Git Bash/Windows 10.
Upvotes: 13
Reputation: 1791
You can use explorer.exe
that can open URL in default browser:
explorer.exe "https://www.google.com/"
Therefore there is a weird bug: URL should not contain ?
, so:
explorer.exe "https://www.google.com/search?q=foo+bar"
will fail, and you need to use:
explorer.exe "https://www.google.com/search?q=foo+bar&\""
to work around.
By the way, I created bash function to open up Google page:
urlencode ()
{
echo $1 | sed -e 's:%:%25:g' -e 's: :%20:g' -e 's:<:%3C:g' -e 's:\[:%5B:g' \
-e 's:>:%3E:g' -e 's:#:%23:g' -e 's:{:%7B:g' -e 's:\*:%2A:g' \
-e 's:}:%7D:g' -e 's:|:%7C:g' -e 's:+:%2B:g' -e 's:\\:%5C:g' \
-e 's:/:%2F:g' -e 's:?:%3F:g' -e 's^:^%3A^g' -e 's:\!:%21:g' \
-e 's:@:%40:g' -e 's:=:%3D:g' -e 's:&:%26:g' -e 's:\$:%24:g' \
-e 's:;:%3B:g' -e 's:~:%7E:g' -e 's:`:%60:g' -e 's:\^:%5E:g' -e 's:\]:%5D:g'
}
google ()
{
local a="$(urlencode "$(echo "$@")")"; a="${a// /+}";
explorer.exe "https://www.google.com/search?q=${a// /+}&\""
}
alias ggle='google'
alias g='google'
You can use it as follows:
g site:cppreference.com c++ empty string view
I find it quite useful, especially while coding ;)
Tested on Bash on Windows (Ubuntu 16.04.3 LTS; GNU bash, wersja 4.3.48).
Upvotes: 3
Reputation: 3657
Here's what I'm using to open a URL or a file with Google Chrome into incognito mode from Git bash (provided with Git for Windows):
sysdm.cpl
and hit the Enter key.Advanced
1 and select Environmental Variables
2Path
3 from System variables
and click on Edit
button4.Keep this window opened (while get the chrome.exe
folder path).
chrome.exe
folder pathRight click (or left if you have your mouse as left-handed) the Chrome icon5 (the one you use to open it) and select Properties
7. Usually this method opens more Chrome actions so locate Google Chrome
option6 and right-click on it and click on Properties
7.
On the Shortcut
8 tab select the folder path from Start in:
9 (Commonly %programfiles(x86)%\Google\Chrome\Application
)
Environment variables
Click on the New
button10 from previously opened Edit environment variable
window and paste the Google Chrome folder path into the new added line11 (delete the double quotes if exist at the beginning or the end of the path) and click on all the OK
buttons from the opened windows.
Open the Git bash terminal and edit (or create) the .bashrc
file with your prefered text editor (Visual Studio code in this example)
code ~/.bashrc
Append the code from below. You can rename the function name (chromeIt
in this example) to your needs.
# Open google Chrome
function chromeIt {
if [ -z "$1" ]; then
# display usage if no parameters given
echo "Usage: chromeIt <file_name>|<url>"
else
if [ -f "$1" ] ; then
chrome --incognito $(pwd)/$1
else
chrome --incognito $1
fi
fi
}
If you don't want incognito mode remove the --incognito
parameter.
Very important note: Verify that your line ending is set as UNIX (LF)12. If you don't know how to do it search into google.
Save the .bashrc
file and reload it (using the Git bash terminal):
source ~/.bashrc
or you can use the shorter version of the command:
. ~/.bashrc
Close the Git bash terminal window or enter exit
and re-open it.
Try to open a URL:
chromeIt google.com
or a file:
chromeIt index.html
I hope it works for you.
Upvotes: 1
Reputation: 2533
You have few options here:
chrome "google.com"
. For me it is C:\Program Files (x86)\Google\Chrome\Application
. This post explains it."C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" google.com
. Please comment if you need more details.
Upvotes: 0
Reputation: 2634
This worked for me on Windows 10 and using Git Bash.
start chrome www.google.com
Upvotes: 43
Reputation: 695
This should do the trick. I can't test on Windows 10 but works fine on bash in Ubuntu
google-chrome http://www.google.com
Upvotes: 0