I have a problem with my terminal / VS Code integrated terminal. When I'm changing directory some directories are with a green background and it's annoying. And I don't know how to disable it. I know that in .zshrc I can disable colors in ls with DISABLE_LS_COLORS="true" but this is not working with cd command.
In the default terminal, it is relatively readable, but in VS Code it is unreadable. Any help?
Add the following line to your .zshrc file
export LS_COLORS="$LS_COLORS:ow=1;34:tw=1;34:"
save the file and then run
source ~/.zshrc
You could just change it for vs code and over ride any theme by changing the settings.json file in settings --> search for workbench --> click edit in settings.json under colour customisations. This should override any theme present from any other add-ons or external terminal mods. I have not tested it before with zshrc though.
In the brackets enter something like this:
"terminal.foreground": "#839496",
"terminal.background": "#002833",
"terminal.ansiBlack": "#003541",
"terminal.ansiBlue": "#268bd2",
"terminal.ansiCyan": "#2aa198",
"terminal.ansiGreen": "#859901",
"terminal.ansiMagenta": "#d33682",
"terminal.ansiRed": "#dc322f",
"terminal.ansiWhite": "#eee8d5",
"terminal.ansiYellow": "#b58901",
"terminal.ansiBrightBlack": "#586e75",
"terminal.ansiBrightBlue": "#839496",
"terminal.ansiBrightCyan": "#93a1a1",
"terminal.ansiBrightGreen": "#586e75",
"terminal.ansiBrightMagenta": "#6c6ec6",
"terminal.ansiBrightRed": "#cb4b16",
"terminal.ansiBrightWhite": "#fdf6e3",
"terminal.ansiBrightYellow": "#657b83",
"terminalCursor.foreground": "#839496",
"terminalCursor.background": "#003541"
Related
I am trying to update my .bash_profile but the changes are not being reflected.
When I type ~/.bash_profile in command line, i get the error "zsh: No such file or directory: Users/My.Name/.bash_profile".
Why can't terminal find it? How do I help it locate the file? When I go to Users/My.Name directory and show hidden files, the .bash_profile is there.
If you type
~/.bash_profile
on your command line while using zsh, as it seems you do, if the file exists you'll receive
zsh: permission denied: /Users/username/.bash_profile
because usually the file does not have execute permission set.
You could source the file, but it's not a good idea to load init files from different shells as syntax differs.
The reason why terminal can't find your .bash_profile is because you are using zsh as your default shell, not bash. Zsh is a newer and it has its own configuration file called .zshrc. If you want to update your zsh settings, you need to edit the .zshrc file instead of the .bash_profile file.
To help terminal locate the file, you can use the full path of the file instead of the relative path. The full path starts with a slash (/) and specifies the exact location of the file in the file system. The relative path starts with a tilde (~) and specifies the location of the file relative to your home directory. For example, the full path of your .zshrc file is /Users/My.Name/.zshrc, while the relative path is ~/.zshrc.
To edit the .zshrc file, you can use any text editor of your choice, such as nano, vim, or VS Code. For example, to edit the file using nano, you can type the following command in terminal:
nano /Users/My.Name/.zshrc
This will open the file in nano, where you can make your changes and save them. To exit nano, press Ctrl+X, then Y, then Enter.
Explanation
A shell is a program that interprets your commands and runs them on your computer. There are different types of shells, such as bash, zsh, ksh, and csh. Each shell has its own syntax, features, and configuration files. You can check which shell you are using by typing the following command in terminal:
echo $SHELL
This will print the full path of your current shell. For example, if you are using zsh, it will print /bin/zsh.
A configuration file is a file that contains settings and preferences for your shell. It is usually hidden, meaning that it starts with a dot (.). It is executed every time you open a new terminal session, so it can affect your environment variables, aliases, functions, and other aspects of your shell. For example, you can use a configuration file to change your prompt, set your PATH, or enable some plugins.
The most common configuration file for bash is .bash_profile, while the most common configuration file for zsh is .zshrc. They are usually located in your home directory, which is the directory that contains your personal files and folders. You can access your home directory by typing ~ in terminal.
To edit a configuration file, you need to use a text editor, which is a program that allows you to create and modify text files. There are many text editors available, such as nano, vim, VS Code, Sublime Text, and Atom. Each text editor has its own commands, shortcuts, and features. For example, nano is a simple and easy-to-use text editor that runs in terminal, while VS Code is a powerful and modern text editor that runs in a graphical user interface.
Examples
Here are some examples of how to edit your .zshrc file using different text editors:
To edit the file using vim, type the following command in terminal:
vim /Users/My.Name/.zshrc
This will open the file in vim, where you can make your changes and save them. To exit vim, press Esc, then :, then x, then Enter.
To edit the file using VS Code, type the following command in terminal:
code /Users/My.Name/.zshrc
This will open the file in VS Code, where you can make your changes and save them. To exit VS Code, click on the red X button on the top left corner of the window.
To edit the file using Sublime Text, type the following command in terminal:
subl /Users/My.Name/.zshrc
This will open the file in Sublime Text, where you can make your changes and save them. To exit Sublime Text, click on the red X button on the top right corner of the window.
I'm having trouble setting up Sublime Text for bash on Windows Powershell. I would like to use Sublime Text instead of emacs or vi. I got it to work once but every time I close the terminal it stops working.
I used
alias subl='"/mnt/c/Program Files/Sublime Text 3/sublime_text.exe"'
and this works but after I close the terminal and reopen it, it does not recognize the command anymore.
When running bash.exe either from the powershell or calling bash.exe directly, windows doesn't appear to make your default directory your home! Thats maybe why perhaps you cannot see .bashrc as other have mentioned. So in order to make your alias persistent..
Move to your home direcotry:
cd ~
vim .bash_profile
I use .bash_profile but as others have mentioned you could/can add it to .bashrc
Add this into your .bash_profile:
alias subl=' "/mnt/c/Program Files/Sublime Text 3/sublime_text.exe"'
Now every time you login, .bash_profile will load and in turn your alias
subl
Will see Sublime text load for you
I would recommend a slightly clener way. Add this to your .bash_profile instead:
export PATH="/mnt/c/Program Files/Sublime Text 3":$PATH
Now you can simply just run:
sublime_text.exe
in WIN 10
do
WIN + pause
select Advanced settings
select Environment Variables
add the path to sublime to the env variable list
I am trying to edit an entry to PATH, as I did something wrong.
I am using Mac OS X v10.10.3 (Yosemite)
I have tried:
touch ~/.bash_profile; open ~/.bash_profile
But the file editor opens with nothing inside.
My problem:
I am trying to install ANDROID_HOME to my PATH
I misspelled it, but when I closed the terminal and went back it was gone, so I tried again:
export ANDROID_HOME=/<installation location>/android-sdk-macosx
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
This time, I typed the command correctly but, when I closed the terminal, my settings disappeared again.
How do I execute my desired settings?
If I was to edit bash.profile, how would I enter the above code?
You have to open that file with a text editor and then save it.
touch ~/.bash_profile; open ~/.bash_profile
It will open the file with TextEdit, paste your things and then save it. If you open it again you'll find your edits.
You can use other editors:
nano ~/.bash_profile
mate ~/.bash_profile
vim ~/.bash_profile
But if you don't know how to use them, it's easier to use the open approach.
Alternatively, you can rely on pbpaste. Copy
export ANDROID_HOME=/<installation location>/android-sdk-macosx
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
in the system clipboard and then in a shell run
pbpaste > ~/.bash_profile
Or alternatively you can also use cat
cat > ~/.bash_profile
(now cat waits for input: paste the two export definitions and then hit Ctrl + D).
A bit more detailed for beginners:
Before you begin with .bash_profile on Mac, please be aware that since macOS Catalina zsh (z shell) is the default shell. Therefore stuff we used to put in the .bash_profile now belongs to the .zshenv or the .zshrc file.
.zshenv .zshrc ? (Found here)
.zshenv: invocations of the shell. Often contains exported variables that should be available to other programs. For example, $PATH.
.zshrc: Sourced in interactive shells only. It should contain commands to set up aliases, functions, options, key bindings, etc.
STEP 1
Make sure the .bash_profile file is existing? (or the .zshenv of course) Remember that the .bash_profile file isn't there by default. You have to create it on your own.
Go into your user folder in finder.
The .bash_profile file should be findable there.
-> HD/Users/[USERNAME]
Remember: Files with a point at the beginning '.' are hidden by default.
To show hidden files in Mac OS Finder:
Press: Command + Shift + .
If it's not existing, you have to create .bash_profile on your own.
Open terminal app and switch into user folder with simple command:
cd
If it's not existing, use this command to create the file:
touch .bash_profile
STEP 2
If you can't memorise the nerdy commands for save and close in vim, nano etc (the way recommended above) the easiest way to edit is to open .bash_profile (or the .zshenv) file in your favored code editor (Sublime, Visual Studio Code, etc.).
Finder -> User folder. Right click -> open with : Visual Studio Code (or other code editor). Or drag it on app in dock.
… and there you can edit it, pass export commands in new lines.
If you are using macOS v10.15 (Catalina), you need to update the .zshrc file instead of file .bash_profile or .profile.
For Mac OS, step by step:
First of all, open a terminal and write it: cd ~/
Create your Bash file: touch .bash_profile
You created your ".bash_profile" file, but if you would like to edit it, you should write it;
Edit your Bash profile: open -e .bash_profile
After that you can save from the top-left corner of screen: File → Save
For beginners: To create your .bash_profile file in your home directory on macOS, run:
nano ~/.bash_profile
Then you can paste in the following:
https://gist.github.com/mocon/0baf15e62163a07cb957888559d1b054
As you can see, it includes some example aliases and an environment variable at the bottom.
One you're done making your changes, follow the instructions at the bottom of the Nano editor window to WriteOut (Ctrl + O) and Exit (Ctrl + X). Then quit your Terminal and reopen it, and you will be able to use your newly defined aliases and environment variables.
Set the path JAVA_HOME and ANDROID_HOME. You have to open terminal and enter the below cmd.
touch ~/.bash_profile; open ~/.bash_profile
After that, paste the below paths in the base profile file and save it:
export ANDROID_HOME=/Users/<username>/Library/Android/sdk
export PATH="$JAVA_HOME/bin:$ANDROID_HOME/platform-tools:$ANDROID_HOME/emulator:$PATH"
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home
Just type open ~/.bash_profile on terminal, you can edit it.
Determine which shell you're using by typing echo $SHELL in Terminal.
Then open/create correct rc file. For Bash it's $HOME/.bash_profile or $HOME/.bashrc. For Z shell it's $HOME/.zshrc.
Add this line to the file end:
export PATH="$PATH:/your/new/path"
To verify, refresh variables by restarting Terminal or typing source $HOME/.<rc file> and then do echo $PATH
Mac OS X doesn't store the path in file .bash_profile, but file .profile, since Mac OS X is a branch of the *BSD family. You should be able to see the export blah blah blah in file .profile once you do cat .profile on your terminal.
For me, my macOS is macOS v10.14 (Mojave). And I was facing the same issue for three days and in the end, I just wrote the correct path in the .bash_profile file which was like this:
export PATH=/Users/[YOURNAME]/development/flutter/bin:$PATH
Note 1: if you don't have filr .bash_profile, create one and write the line above
Note 2: zip your downloaded Flutter SDK in [home]/development if you copy and paste this path
The simplest answer is:
Step 1: Fire up Terminal.app
Step 2: Type nano .bash_profile – This command will open the .bash_profile document (or create it if it doesn’t already exist) in the easiest-to-use text editor in Terminal – Nano.
Step 3: Now you can make a simple change to the file. Paste these lines of code to change your Terminal prompt.
export PS1="___________________ | \w # \h (\u) \n| => "
export PS2="| => "
Step 4: Now save your changes by typing Ctrl + O. Hit Return to save. Then exit Nano by typing Ctrl + X
Step 5: Now we need to *activate your changes. Type source .bash_profile and watch your prompt change.
That's it! Enjoy!
I am trying to edit an entry to PATH, as I did something wrong.
I am using Mac OS X v10.10.3 (Yosemite)
I have tried:
touch ~/.bash_profile; open ~/.bash_profile
But the file editor opens with nothing inside.
My problem:
I am trying to install ANDROID_HOME to my PATH
I misspelled it, but when I closed the terminal and went back it was gone, so I tried again:
export ANDROID_HOME=/<installation location>/android-sdk-macosx
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
This time, I typed the command correctly but, when I closed the terminal, my settings disappeared again.
How do I execute my desired settings?
If I was to edit bash.profile, how would I enter the above code?
You have to open that file with a text editor and then save it.
touch ~/.bash_profile; open ~/.bash_profile
It will open the file with TextEdit, paste your things and then save it. If you open it again you'll find your edits.
You can use other editors:
nano ~/.bash_profile
mate ~/.bash_profile
vim ~/.bash_profile
But if you don't know how to use them, it's easier to use the open approach.
Alternatively, you can rely on pbpaste. Copy
export ANDROID_HOME=/<installation location>/android-sdk-macosx
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
in the system clipboard and then in a shell run
pbpaste > ~/.bash_profile
Or alternatively you can also use cat
cat > ~/.bash_profile
(now cat waits for input: paste the two export definitions and then hit Ctrl + D).
A bit more detailed for beginners:
Before you begin with .bash_profile on Mac, please be aware that since macOS Catalina zsh (z shell) is the default shell. Therefore stuff we used to put in the .bash_profile now belongs to the .zshenv or the .zshrc file.
.zshenv .zshrc ? (Found here)
.zshenv: invocations of the shell. Often contains exported variables that should be available to other programs. For example, $PATH.
.zshrc: Sourced in interactive shells only. It should contain commands to set up aliases, functions, options, key bindings, etc.
STEP 1
Make sure the .bash_profile file is existing? (or the .zshenv of course) Remember that the .bash_profile file isn't there by default. You have to create it on your own.
Go into your user folder in finder.
The .bash_profile file should be findable there.
-> HD/Users/[USERNAME]
Remember: Files with a point at the beginning '.' are hidden by default.
To show hidden files in Mac OS Finder:
Press: Command + Shift + .
If it's not existing, you have to create .bash_profile on your own.
Open terminal app and switch into user folder with simple command:
cd
If it's not existing, use this command to create the file:
touch .bash_profile
STEP 2
If you can't memorise the nerdy commands for save and close in vim, nano etc (the way recommended above) the easiest way to edit is to open .bash_profile (or the .zshenv) file in your favored code editor (Sublime, Visual Studio Code, etc.).
Finder -> User folder. Right click -> open with : Visual Studio Code (or other code editor). Or drag it on app in dock.
… and there you can edit it, pass export commands in new lines.
If you are using macOS v10.15 (Catalina), you need to update the .zshrc file instead of file .bash_profile or .profile.
For Mac OS, step by step:
First of all, open a terminal and write it: cd ~/
Create your Bash file: touch .bash_profile
You created your ".bash_profile" file, but if you would like to edit it, you should write it;
Edit your Bash profile: open -e .bash_profile
After that you can save from the top-left corner of screen: File → Save
For beginners: To create your .bash_profile file in your home directory on macOS, run:
nano ~/.bash_profile
Then you can paste in the following:
https://gist.github.com/mocon/0baf15e62163a07cb957888559d1b054
As you can see, it includes some example aliases and an environment variable at the bottom.
One you're done making your changes, follow the instructions at the bottom of the Nano editor window to WriteOut (Ctrl + O) and Exit (Ctrl + X). Then quit your Terminal and reopen it, and you will be able to use your newly defined aliases and environment variables.
Set the path JAVA_HOME and ANDROID_HOME. You have to open terminal and enter the below cmd.
touch ~/.bash_profile; open ~/.bash_profile
After that, paste the below paths in the base profile file and save it:
export ANDROID_HOME=/Users/<username>/Library/Android/sdk
export PATH="$JAVA_HOME/bin:$ANDROID_HOME/platform-tools:$ANDROID_HOME/emulator:$PATH"
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home
Just type open ~/.bash_profile on terminal, you can edit it.
Determine which shell you're using by typing echo $SHELL in Terminal.
Then open/create correct rc file. For Bash it's $HOME/.bash_profile or $HOME/.bashrc. For Z shell it's $HOME/.zshrc.
Add this line to the file end:
export PATH="$PATH:/your/new/path"
To verify, refresh variables by restarting Terminal or typing source $HOME/.<rc file> and then do echo $PATH
Mac OS X doesn't store the path in file .bash_profile, but file .profile, since Mac OS X is a branch of the *BSD family. You should be able to see the export blah blah blah in file .profile once you do cat .profile on your terminal.
For me, my macOS is macOS v10.14 (Mojave). And I was facing the same issue for three days and in the end, I just wrote the correct path in the .bash_profile file which was like this:
export PATH=/Users/[YOURNAME]/development/flutter/bin:$PATH
Note 1: if you don't have filr .bash_profile, create one and write the line above
Note 2: zip your downloaded Flutter SDK in [home]/development if you copy and paste this path
The simplest answer is:
Step 1: Fire up Terminal.app
Step 2: Type nano .bash_profile – This command will open the .bash_profile document (or create it if it doesn’t already exist) in the easiest-to-use text editor in Terminal – Nano.
Step 3: Now you can make a simple change to the file. Paste these lines of code to change your Terminal prompt.
export PS1="___________________ | \w # \h (\u) \n| => "
export PS2="| => "
Step 4: Now save your changes by typing Ctrl + O. Hit Return to save. Then exit Nano by typing Ctrl + X
Step 5: Now we need to *activate your changes. Type source .bash_profile and watch your prompt change.
That's it! Enjoy!
I want to change the default terminal app used by Visual Studio Code for Mac. I am thinking it is part of preferences or settings json, but unsure.
Here's an example of how to make another terminal the default for VSCode, in this example I've downloaded iTerm2 and copied iTerm2 to Applications.
Code (Menu) > Preferences > User Settings
Edit settings.json "terminal.external.osxExec": "iTerm.app" and "terminal.explorerKind": "external"
Open in Terminal
iTerm is now default terminal launched from VSCode
For those that want to change the default integrated terminal NOT just the external, and add custom themes, show which git branch you are on, and whether or not files need to be staged or committed for example.
Follow these short steps:
Make sure you have these installed:
iTerm2, oh-my-zsh
Install a powerline font (I am using Menlo which is a nice looking and very popular font).
Go here and click on download
Open the file
Click on install font
(Note: without this, vscode integrated terminal will not render themes correctly)
Open the .zshrc file by running this command:
cd ~ ; code .zshrc
Change iTerm's theme to agnoster:
Press ⌘f to open search in the .zshrc file
Type ZSH_THEME
Search until you find the live code, NOT the commented out code :)
Edit the code it so it looks like ZSH_THEME="agnoster"
Save the file
Open vscode settings using shortcut:
⌘,
Inside of vscode settings, you will see two panels. On the right panel paste this:
"terminal.external.osxExec": "iTerm.app",
"terminal.integrated.shell.osx": "/bin/zsh",
"terminal.integrated.fontFamily": "Menlo for Powerline"
Assuming the settings were empty before, it should now look like this:
{
"terminal.external.osxExec": "iTerm.app",
"terminal.integrated.shell.osx": "/bin/zsh",
"terminal.integrated.fontFamily": "Menlo for Powerline"
}
Finished! Enjoy your new pimped out terminal
-(Optional customization)-
If you want your prompt to display something other than your username such as a thunder bolt, like in mine or anything you want
Open agnoster theme by runnning this command:
cd ~/.oh-my-zsh/themes/ ; code agnoster.zsh-theme
Open search by pressing:
⌘f
Paste this in search bar:
prompt_segment black default "%(!.%{%F{yellow}%}.)$USER#%m"
To change your what your prompt displays, edit ONLY this part:
$USER#%m
DO NOT CHANGE this part:
prompt_segment black default "%(!.%{%F{yellow}%}.)
In conclusion, the code should now look something like this:
prompt_segment black default "%(!.%{%F{yellow}%}.) Insert here whatever your heart desires"
(Note: Technically you can change everything about your terminal prompt, but for the sake of keeping this short, and simple we only edited the username part)
None of these answers fully worked for me. Here is what I changed to get it to work:
Select the default shell as zsh:
CMD + SHIFT + P to open up the command palette. Then type Terminal: Select Default Shell. You can then select zsh.
Change the terminal to use iTerm
Change the font family to use Powerlevel10k
Result
I recently changed my terminal in VSCode to ozh, its just 1 step and 1 line.
Open Command Palette using View > Command Palette
( or simply Command + Shift + P )
add the following line to the user settings.
"terminal.integrated.shell.osx": "zsh"
well I know it's so late, but you could just change it by running command
Terminal: Select Default Shell
its so much easier
From visual studio code blog:
// 64-bit cmd it available, otherwise 32-bit
"terminal.integrated.shell.windows":"C:\\Windows\\sysnative\\cmd.exe"
// 64-bit PowerShell if available, otherwise 32-bit
"terminal.integrated.shell.windows":"C:\\Windows\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe"
// Git Bash
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe"
// Bash on Ubuntu (on Windows)
"terminal.integrated.shell.windows": "C:\\Windows\\sysnative\\bash.exe"
Reference: Integrated Terminal
In vscode settings.json add:
"terminal.integrated.profiles.osx": {
"zsh": null
},
No. But you can vote for this feature here: https://visualstudio.uservoice.com/forums/293070-visual-studio-code