I am using:
Mac OS X 10.10.5 (Yosemite)
zsh 5.0.5
oh-my-zsh
the problem is, terminal load time is too slow about 10 seconds, even for opening new terminal tabs.
I tried solution on this blog post: http://osxdaily.com/2010/05/06/speed-up-a-slow-terminal-by-clearing-log-files/ but that didn't helped me.
sudo rm -rf /private/var/log/asl/*.asl
Thanks
node was making trouble for me, and here is the solution that works:
In my .zshrc
# configure node version manager
export NVM_DIR=~/.nvm
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" --no-use # This loads nvm
alias node='unalias node ; unalias npm ; nvm use default ; node $#'
alias npm='unalias node ; unalias npm ; nvm use default ; npm $#'
For more information visit:
https://github.com/creationix/nvm/issues/539#issuecomment-245791291
Thanks
These are the steps which I have used to optimize my shell startup speed and reducing lag in executing commands -
If you are using powerlevel9k, then I will recommend to immediately switch to powerlevel10k.
Powerlevel10k is a theme for Zsh. It emphasizes speed, flexibility and out-of-the-box experience. It is a reimplementation of the popular Powerlevel9k zsh theme. It looks exactly the same given the same configuration but renders prompt 10-100 times faster. It's optimized on every level of the stack, all the way down to using a patched version of libgit2 that can scan a repo 4 times faster than the original. It can remove Zsh startup lag even if it's not caused by a theme with features such as Instant Prompt.
Go to Preferences -> Profiles -> General -> Command and select the option Command instead of Login Shell and paste the below command in the box nearby it.
login -pfq username /usr/local/bin/zsh -il
You wouldn't see the last login time printed when starting a new tab now. If zsh is not present in the location /usr/local/bin/zsh, you will need to install zsh using brew. The default zsh provided by mac is at /usr/bin/zsh and might be using an older version like 5.2 which can cause slow speed when used with iTerm or oh-my-zsh.
To make pasting in zsh fast, execute the below command in the terminal.
mkdir -p $ZSH_CUSTOM/lib && touch $ZSH_CUSTOM/lib/misc.zsh
Point 2 should already take care of slow login times. But just for safety execute the below command
mkdir -p .hushlogin
There are tons of plugins you might be using which are slow and creates lag. You need to point out these plugins and remove them. For this, you will need zsh profiling. Follow this link for more details -
https://stevenvanbael.com/profiling-zsh-startup
Please comment all the git prompt code in your theme.
zsh on my mac was very slow. Any command, like cd, ls took 2-5 seconds, but after I commented on all the git prompt code in the theme, things become totally different.
Enjoy the smooth again!
I know this is a very old question but I tried all previous answers and the problem came back after some time. I did as much as to git rid of oh-my-zsh completely. But the actual culprit was .zsh-history. My history file was holding more than 1000 commands and was slowing down zsh. After clearing it zsh went from loading in 10 seconds to 3 seconds.
Here is a simple script to do this automatically.
HISTORY="~/.zsh-history" # Path to zsh history file
HISTORY_LOG="path/to/where/you/wan't/to/save/history"
MAX_HISTORY=100 # Maximum lines to keep in history
if [[ $(expr $(wc -l < $HISTORY) \> $MAX_HISTORY) = "1" ]]; then
cat $HISTORY >> $HISTORY_LOG && echo '' > $HISTORY
fi
Add this script to run on startup and it will clear out your history when it reaches over 100 lines. I save it to another location in case I wan't to find something in it later.
You could also change the script to always keep 100 lines in your history. That is to remove the first n lines so as to keep the number of lines 100. But I personally like this approach better.
Related
When I run basic commands like pwd and cd the command itself executes fast but the console hangs for 1 second before allowing me to execute another command.
I got the latest Git Bash portable and tried
32- and 64-bit
Run as admin
sh.exe instead of git-bash.exe (and Run as admin)
But Cygwin does not have this problem.
In Cygwin, running pwd from the same directory as any Git Bash variant results in equally fast command completion but also there is no console hanging.
My Windows is: Version 10.0.19044 Build 19044
I have nVidia Quadro P3000
UPDATE from comments below:
It appears to be an issue with my Git installation but I chose the defaults so I don't know what it could be.
When I execute PS1='$ ' in Git-Bash, I do not have the the 1-second pause after each command is executed.
UPDATE from comments below
$ echo ${PS1#A}
declare -x PS1='\[\033]0;$TITLEPREFIX:$PWD\007\]\n\[\033[32m\]\u#\h \[\033[35m\]$MSYSTEM \[\033[33m\]\w\[\033[36m\]`__git_ps1`\[\033[0m\]\n$ '
I did not change anything.
I download a version of portable Git For Windows, launch as admin and type ls, pwd, etc.
I went back to 2.24 but same behavior.
I'm also going to try it on my personal PC since it could be my corporate antivirus that's causing this.
UPDATE
The issue is __git_ps1 and there's an open issue
I think that __git_ps1 is the culprit.
As a test, put following code in /tmp/experiment.sh
if [[ "$(type -t __git_ps1)" == 'function' ]]; then
cd(){
builtin cd "$#"
__GIT_PS1=$('__git_ps1') # Calling original __git_ps1, only when changing directory.
}
__git_ps1_stub(){
echo "$__GIT_PS1" # Now $PS1 will do this echo, instead of calling __git_ps1
}
alias __git_ps1=__git_ps1_stub # __git_ps1_stub will be called in $PS1
cd . # Initialize $__GIT_PS1 for the first time.
fi
Then start a git-bash terminal, and run source /tmp/experiment.sh
If situation improves, you can put the code in ~/.bashrc
You'll need to change other commands (like pushd, popd, etc) if you use them to change directory.
Try first to simplify your PATH when testing your Git bash.
In a CMD, type
set "GH=C:\Program Files\Git"
set "PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0"
set "PATH=%GH%\bin;%GH%\cmd;%GH%\usr\bin;%GH%\mingw64\bin;%GH%\mingw64\libexec\git-core;%PATH%"
Then try again and type bash to enter a shell session.
By default, I get:
$ echo $PS1
\[\033]0;$TITLEPREFIX:$PWD\007\]\n\[\033[32m\]\u#\h \[\033[35m\]$MSYSTEM \[\033[33m\]\w\[\033[36m\]`__git_ps1`\[\033[0m\]\n$
And it is quite fast.
(Microsoft Windows 10.0.19044.1586, git version 2.35.1.windows.2)
The problem may be related to slow resolution of computer network names. Since the computer name is involved in the command line. I advise you to add yourhostname and localhost to etc/hostname.
For me it was corrupt page file. Try clearing Windows page file and rebooting. Page file was constantly causing my git bash to hang for 20 seconds with just carriage returns. I've re-enabled page file several times and eventually it happens again. Clearing page file fixed it every time.
I turn page file completely off now and git bash is screaming fast.
I'm running IntelliJ 2018.3 on Windows 7, as well as openSUSE Leap 15.
Under Windows 7, I've configured IntelliJ to use Git Bash, i.e., in Settings, under Tools -> Terminal, I'm setting Shell path to:
C:\Program Files (x86)\Git_2.17.1\bin\bash.exe
One of IntelliJ's new features is the ability to save and reload terminal sessions (see this link).
It works perfectly with openSUSE, however, on Windows, while the terminal tab names are correctly restored, I always end up with a new shell.
Is there a way to make IntelliJ and Git Bash play well together so that I can retain the current working directory and shell history after restarting IntelliJ?
You can try and setup your Git for Windows bash to remember the last used path for you, as seen in "How can I open a new terminal in the same directory of the last used one from a window manager keybind?"
For instance:
So instead of storing the path at every invocation of cd the last path can be saved at exit.
My ~/.bash_logout is very simple:
echo $PWD >~/.lastdir
And somewhere in my .bashrc I placed this line:
[ -r ~/.lastdir ] && cd $(<~/.lastdir)
That does not depend on Intellij IDEA directly, but on the underlying bash setup (here the Git for Windows bash referenced and used by Intellij IDEA.
Here's a possible workaround. It was heavily inspired by VonC's answer, as well as other answers to the question that he mentioned.
~/.bashrc
if [[ -v __INTELLIJ_COMMAND_HISTFILE__ ]]; then
__INTELLIJ_SESSION_LASTDIR__="$(cygpath -u "${__INTELLIJ_COMMAND_HISTFILE__%history*}lastdir${__INTELLIJ_COMMAND_HISTFILE__##*history}")"
# save path on cd
function cd {
builtin cd $#
pwd > $__INTELLIJ_SESSION_LASTDIR__
}
# restore last saved path
[ -r "$__INTELLIJ_SESSION_LASTDIR__" ] && cd $(<"$__INTELLIJ_SESSION_LASTDIR__")
fi
I don't like the fact that I had to wrap the cd command, however Git Bash does not execute ~/.bash_logout unless I explicitly call exit or logout; unfortunately due to this limitation, the .bash_logout variant is inadequate for the mentioned scenario.
The workaround above also leave small junk files inside __INTELLIJ_COMMAND_HISTFILE__ parent dir, however, I couldn't do any better.
Additionally I've opened a ticket in Jetbrain's issue tracker. There are many different shells that may benefit from official support. It would be great if JetBrains could eventually support powershell and popular terminals like windows-subsystem-for-linux, cygwin and git-bash. The only shell that currently works out of the box for me is cmd.
It is possible to view shorter path in my terminal (VS Code & Hyper) with WSL (Ubuntu). On top of the Ubuntu, I have installed zsh. Currently, I am using a git bash and path looks Lukas#Y50-70 ~/Coding but with the Ubuntu, I have something like this lukas#Y50-70 /mnt/c/Users/Lukas/Coding. When I have a project in another 2 folders or so and I have a long branch name it is annoying to have a full row unnecessary info (for me).
Here is a comparison of Ubuntu and git bash:
Thanks
I was able to solve this using Named Directories - by adding this line to your ~/.zshrc file
hash -d c=/mnt/c
you will see '~c/' in your prompt rather than '/mnt/c/' which I think is a lot nicer.
This has a similar effect to setting an alias for the directory but the name is reflected in how your path is displayed.
As an added bonus you can then switch to that directory at any time by typing ~c
Check if the zsh installation guide under WSL can help (from neurogenesis):
Install zsh with sudo apt-get install zsh
bash.exe is the entrypoint to the WSL / linux subsystem. You'll have to modify the windows shortcut to specify bash -c --login or modify ~/.bashrc with exec /bin/zsh to properly load a different shell.
/etc/passwd isn't consulted because it's not a full login process. Be sure to set your SHELL env var as well. See #846 for details.
Fix your umask before you start installing things, otherwise tools like zsh will complain.
Specifically, "group" and "other" permissions will have the same privileges that owner do. This causes zsh's compaudit and compinit to fail (both are related to command completion).
See #352 for details. umask 022 can be added to your ~/.bashrc.
NOTE: This should be done before trying to install zsh plugin managers like antigen (otherwise the directory/file permissions issues from git clones).
You should also do this before installing RVM or rbenv.
I ended up inserting a few lines to the top of my ~/.bashrc, something like the following:
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
## Fix missing umask value
umask 022
## Launch Zsh
if [ -t 1 ]; then
cd $HOME
export SHELL=/bin/zsh
exec -cl $SHELL
fi
Issue 846 (mentioned in point 2) includes the comment:
A normal -c zsh symlink opened up in the wrong directory to me, but I managed using this (note the tilde):
C:\Windows\System32\bash.exe ~ -c /bin/zsh
See also "How to Use Zsh (or Another Shell) in Windows 10".
I know this isn't exactly the fix you were hoping for. I was looking to solve the same issue. The prompt was just too long and it was causing some of my commands to wrap to the next line. After seeing the comments on VonC's answer, I'm deciding to keep my next-best solution.
What I did in my ~/.bashrc file is this:
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u#\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\n\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u#\h:\w\n\$ '
fi
I added a \n right before the \$
So when I'm at my Windows home folder, it looks like this
ryan#DESKTOP-RSKAA4F:/mnt/c/Users/ryank
$
And I start typing my commands after the $. It takes up more vertical space, but at least I don't have to maximize my terminal window just to avoid text wrap.
It appears to me that just running 'cd' after starting the terminal session, re-bases the prompt to the normal '/home/(user)'
there should be no need for installing zsh or anything else. It works for me anyway.
also when starting the session at the root folder from windows, seems to do the trick.
I keep my sessions under
C:\vms
sample:
cd -d C:\vms\minikube\ubu_jenkinsX\rootfs
C:\vms\minikube\ubu_jenkinsX\rootfs>wsl -d ubu_jenkinsX
Yours may be under your userprofile in local data. Search for the rootfs folder
The reason your WSL prompt shows such a long path is because you're not actually in your home directory. You see, WSL has its own virtual filesystem separate from Windows, and Windows paths (like your C:\Users\Lukas\...) are stored under /mnt/c/Users/Lukas/.... Your WSL home directory would be /home/Lukas (since your WSL username is capitalized), but of course, that's not where your project is.
The fish shell has a prompt_pwd function that shortens a path to something like this:
0 ---- /m/c/U/L/Documents cd Something
0 ---- /m/c/U/L/D/Something prompt_pwd
/m/c/U/L/D/Something
Is that something you're interested in? You could port the function to Bash, or just switch to Fish, or just display the current directory name instead of path.
I'm getting an error message when I first open my Mac terminal -
-bash: Applications: command not found
Oddly (or maybe not so oddly), when I open another tab, I sometimes get a different error -
-bash: README.md: command not found
or
-bash: [: missing `]'
I just noticed that this morning... there are two things that I did last night that I feel may have led to this, but I'm not sure if I am correct, nor do I know how to appropriately fix this issue. My OS is El Capitan 10.11.13.
First off, last night, I used Homebrew to install PostGIS 2.2 - my Postgres version is 9.5.1.
Second, I made a Github pull request for one of my projects (I'm not sure how a pull request could upset my bash profile, but Github's standard readme format is README.md, so I thought I'd better mention this here).
My bash profile seems clean to me -
[[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function
export PATH=${PATH}:/usr/local/mysql/bin
* #EDITED TO INCLUDE THIS ASTERISK, WHICH I NEGLECTED BEFORE
Can anyone shed some light on what happened and how I can go about fixing this? I'm fairly new to using the terminal, so I'm not quite sure how to interpret this.
How to troubleshoot Bash startup problems:
To build on Jonathan Leffler's helpful comment:
From an existing terminal window, run script log.txt bash -lxv
This will create a new login (-l) shell (which is the type of shell Terminal.app on OSX creates by default) and log all its startup activities.
In addition to capturing regular output,
-v shows unexpanded source lines as they're being read.
-x shows the expanded, individual commands that are executed, prefixed with +.
Execute exit to terminate that shell, which will save everything that was just printed to log.txt.
Study file log.txt to see what's going on.
What turned out to be the OP's problem:
A stray * on a single line in their profile expanded to an alphabetically sorted list of the names of the files and folders in the then-current directory (a process called pathname expansion or globbing).
Not only is a * as its own command (or the start of a command) not useful, it could result in unwanted execution of a command (see below).
Bash then tried to execute the result of this expansion as a command to execute, with the 1st word (whitespace-separated token) interpreted as the command name.
This failed, because that first word happened not be a command name.
However, if the first word happened to be a valid command name such as file, that command would execute.
(Unless the current dir. happens to be in the $PATH, it doesn't matter whether the first matching filename is an executable file or not - all that matters is whether the name matches an existing command name).
On startup, the user's home dir. was the working dir.; by contrast, opening another tab later uses the then-current working dir., whatever it happens to be.
This explains the differing symptoms, as globbing in different directories will typically result in different name lists, the respective first word of which Bash will try to execute.
Thanks to everyone's help here, I was able to resolve this issue. When I posted my question, I left a tiny but important detail out of my bash profile - a lone asterisk on the last line.
[[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function
export PATH=${PATH}:/usr/local/mysql/bin #ADDS MYSQL TO PATH EVERY TIME TERMINAL OPENS
*
I didn't even notice this thing before, let alone understand that it was doing anything. I commented it out and now everything runs perfectly. I'm not sure if this asterisk is a standard part of the bash profile or not, but if it has been there all along, it didn't cause me any trouble until this morning, after I had installed PostGIS and made a Github pull request. I'm not sure why those actions would have triggered this problem, but I'm trying to be as descriptive as possible in case anyone else runs into this.
I installed RVM system wide on Fedora 14, and I pretty much followed the guide to the letter. When I tried it out though:
$ type rvm | head -n1
rvm is /usr/local/bin/rvm
Most commands appear to work fine, but changing Rubies doesn't work properly. I have to keep logging off and back in for it to switch, and that doesn't seem to work every time.
Here's exactly what I did:
bash < <( curl -L http://bit.ly/rvm-install-system-wide ) as root
add my own user to the rvm group
add
[[ -s "/usr/local/lib/rvm" ]] && source "/usr/local/lib/rvm"
to the very end of ~/.bash_profile.
Log off and back in.
If I understood correctly, this is exactly what should be done. I made sure .bashrc doesn't contain a return statement.
I figure this has something to do with the environment variables that RVM sets up. Any thoughts?
Well, I found the answer.
The problem was that I was not running bash as a login shell. This basically means it doesn't execute my ~/.bash_profile.
Embarrassing thing is, on the very, very last point on the troubleshooting guide is written:
If you are using GNOME on Red Hat, CentOS or Fedora ensure that the Run command as login shell option is checked under the Title and Command tab in Profile Preferences. After changing this setting, you may need to exit your console session and start a new one before the changes take affect.
Looks like I didn't actually read the whole thing, but Wayne does need to put "Make sure you're running the shell as a login shell" on the guide itself, not just on the troubleshooting section.