zsh tab completion of directory stack not working - shell

In cd -1, -2, -3 etc in Z shell it appears you can do cd -<tab> and cd +<tab> to do tab-completion of the directory stack. I think it's supposed to work out of the box on zsh?
However this doesn't work for me. I've even tried the suggestions in https://unix.stackexchange.com/a/157773 and that doesn't work either.
I'm using zsh 5.2 (x86_64-unknown-linux-gnu) on archlinux.
The output of setopt is
alwaystoend
autocd
autopushd
cdablevars
extendedhistory
histignorealldups
nohup
interactive
interactivecomments
monitor
nonomatch
promptsubst
pushdminus
shinstdin
zle
How can I make tab completion of the directory stack work?

So, I didn't realize this was a feature but when I tried it in a new tab, it didn't work for me either. But then, after I cd'd around a bit, the tab completion worked as expected. Maybe that's your only issue?
Also, as an alternative method, if you're not using the z plugin, you should check it out. It keeps a global history of all the directories you cd into so that in the future you only have to type a small part of the directory name to get back to it.

Related

macos catalina bash shell not saving history

Last night I went into my bash shell in terminal and entered a few commands. Then today I go in but theyre not saved in the history (arrow up). However the really old commands I used about 5 or more months ago are there, so the history is not empty.
Why is my history no longer activated and how do I activate it?
macOS Catalina uses zsh as your shell, so your shell settings go to ~/.zshrc
Edit your settings:
nano ~/.zshrc
Add these lines to your ~/.zshrc file:
HISTSIZE=100000
HISTFILESIZE=999999
SAVEHIST=$HISTSIZE
The historycommand in zshalso shows only 16 most recent lines from the history file unless you give it the start line as a parameter:
history 0
This will show you the whole history.
You can make an alias for this, so that the history command without the parameter will show the complete history as well:
Add this line to your ~/.zshrc file:
alias history="history 0"
I switched from zsh to bash in OSX Catalina but the shell history wasn't saving. I had success fixing that by creating the ~/.bash_profile file and putting this inside:
export SHELL_SESSION_HISTORY=0
Got the idea from this older thread: https://apple.stackexchange.com/questions/218731/why-bash-history-on-my-mac-wont-save
Since macOS Catalina Apple's default shell is no longer bash, but zsh.
Therefore your sources will no longer come from your .bashrc or .bash_profile.
If you want to bash to be your default shell follow this steps:
System Preferences > Users and groups > right click on your user and select advance options. > On the Login Shell drop down menu select your prefered shell.
Hope this helps!
I solve the problem for myself as follow:
Check which shell is running: echo $SHELL
It should return /bin/bash. Otherwise my solution not applied.
Backup .bash_profile with: mv .bash_profile .bash_profile.bak
Close your shell with CMD + w.
Reopen Terminal to check if bash history works, by typing some commands, then using arrow up to check
If terminal history seems to work again. Then the cause of the error lays down in the .bash_profile. If you want to keep your .bash_profile, you should comment out each of the command in there, to find out which commands cause the problem with the Terminal history.
In my case, the cause was commands of my working place related to cloud tooling.
I hope to help someone out!
Best

How to make tmux get the current working directory from ipython?

Bear with me for a sec while I explain the motivation for my question.
I've tmux set so that it shows the current working directory on the tmux status line. This works fine except in the following scenario:
While on a bash shell, I fire up ipython. On ipython, I change directory to some other place in my disk (doing 'cd some_place'). This works in the sense that I'm cd'ed to that directory, but the tmux status line still shows the original directory from which I fired ipython as the current working directory, instead of the one that I'm now.
I know that this is no bug, tmux is just showing me the original directory, all the "cd's" that I launch from ipython are transparent to that hosting shell.
My question is: Can you think of a way to make tmux get the current working directory from ipython instead of the original (hosting) shell from which it was launched?
Thanks in advance for all your help.
Drawing from this answer, you could manually update the status using a command like the one provided in the linked answer:
!tmux set -qg status-left "#S #P $(pwd)"
Includes the ! for ipython shell calls. This is, however, a manual action. Maybe there is a way to run it automatically.

Unix bash alias not working after start screen

Hi I am having a problem with setting alias in mac after I start the screen command, I have alias for working with git, like
commit=git commit
they work as I expect when I start my terminal (iTerm2), but then sometimes I use screen to have simultaneous instances in remotes servers and virtual machines I work with. After this the alias disappear(command not found).
Does anyone know why or how solve it?
To make the alias work, you must use the alias command. For example, to create an alias in Bash you do:
$ alias commit="git commit"
This works temporarily ie.: in your current shell. In order to make it "stick", you must put it in your ~/.bashrc. That will make it be sourced to all instances of Bash you'll invoke during your terminal session.
When you start screen, it starts a separate Bash too, so you'll be covered.
You write something about VMs. If you need this alias to work there, you must make ~/.bashrc on these VMs to have the same aliases. But that's the other story. You should already know how to achieve what you want.
You need to make sure your aliases are defined in ~/.bashrc to ensure they get included in all logins. You can test this out: edit your ~/.bashrc to include this line:
echo "bashrc"
And then edit your ~/.bash_profile to include this line:
echo "bash_profile"
You'll see when you start screen that only "bashrc" is displayed.
See this question for much more detail on the subject.

Zsh show fail every time when I open my terminal

I'm using a Mac with OS X Yosemite and Zsh.
By accident,I delete the content of three files below:
.bashrc
.bash_profile
.profile
After that ,when I open my terminal.
The Zsh will show fail under the last login information,it confused me ,and I want to know why.
You might want to look at a duplicate question: Zshell starts up with exit status of 1 after uninstalling RVM
It has an answer that solved the issue for me:
I found a .zlogin file on my system that contained some rvm-related code. I've deleted the code, and the problem is solved!
Zsh (by default) doesn't read from .bashrc, .bash_profile, or .profile, so the contents of these files shouldn't matter. You also didn't mention which .bashrc, .bash_profile, and .profile were erased… These files exist in both your /Users/username directory and /etc. The files sourced by zsh at startup are listed in the OS X zsh man page (man zsh in a terminal) under "STARTUP/SHUTDOWN FILES". The only reason it would call one of the previously mentioned files is if they were explicitly sourced in one of the default files.
My suggestions:
Check the contents of /etc/zshenv (this is the only zsh-specific file in my etc directory). Mine has only the following:
# system-wide environment settings for zsh(1)
if [ -x /usr/libexec/path_helper ]; then
eval `/usr/libexec/path_helper -s`
fi
Can you log in at all using zsh? If not, can you log in using another shell? You can do this in the OS X Terminal.app by going to Preferences -> General and changing the option for "Shells open with:" from "Default login shell" to Command (fill in another shell, i.e., /bin/bash or /bin/sh). If you can log in with any shell, try the following solution from this question:
Looking for the error
All shell output goes to the terminal, so you could just redirect it
when starting it. As you are looking for error messages during
initialisation, I'd suggest the following procedure:
Disable the problematic configurations
Open a terminal
Check the value of SHLVL: echo $SHLVL
Re-enable the configurations
Start a new z-shell from within the running shell with zsh 2> zsh-error.log, this redirects stderr to the file 'zsh-error.log'.
Check the value of SHLVL again. If it is bigger then previous value then exit the current shell (exit). (Explanation below)
Have a look at 'zsh-error.log' in the current directory.
If 'zsh-error.log' does not show anything, you may want to run zsh -x
2> zsh-error.log in step 5 instead. This provides a complete debug
output of anything zsh does. This can get quite huge.
As the answer suggests, those logs can get enormous if you are sourcing man files at startup. Just a bare shell should result in a reasonably small log file.
Finally, you can retrieve a list of all the files sourced by zsh on startup by running zsh -o sourcetrace.
Hope this helps.

dmenu top bar in xmonad runs some items (Chromium), but not ranger or others

I have a "stock" xmonad install on Arch.
No changes to my xmonad.hs yet
I have installed dmenu.
It runs by alt-p, the default, and displays and filters as expected.
Chromium runs, but other items, like ranger, alsamixer or other tasks do not.
I am not finding anything anywhere about anyone having to do anything to get these items to run, nor anyone having any issues with doing so.
Surely, then, there is something wrong in my install.
my dmenu_run is as follows:
#!/bin/sh
dmenu_path | dmenu "$#" | ${SHELL:-"/bin/sh"} &
I would normally run terminology with bash or zsh. I have tried to alter the SHELL to /bin/bash, but to no avail.
Is there any other place I must look or items I should alter?
Such a shame as I am really liking xmonad so far, and want to get dmenu working before I start exploring xmonad.hs...
Thanks in advance
UPDATE: I have found the following
here over at Archwiki that involves changing dmenu_run and adding a .demenu_term in one's home. It seems to work, but still wonder if there was a more orthadox mechanism.
ranger and alsamixer are applications which run inside a terminal. Imagine (or try) to run ls via dmenu, where should the directory listing be printed to without a terminal?
You look for functionality which is provided either by prompt imported from XMonad.Prompt.Shell by using a convinient keybinding like
((modm .|. shiftMask, xK_c), prompt ("xterm" ++ " -e") greenXPConfig)
(described in the linked documentation) or shellPrompt where you execute
xterm -e alsamixer
or any other command, e.g.
feh path/to/image/you/want/to/open/now.jpg
instead of opening a terminal, running above with tailing & and exiting the terminal.

Resources