I have iTerm Build 3.3.9 installed. I have configured oh-my-zsh with following plugins & themes
ZSH_THEME="powerlevel10k/powerlevel10k"
ZSH_DISABLE_COMPFIX="true"
plugins=(aws git colored-man-pages colorize github virtualenv pip python osx zsh-syntax-highlighting zsh-completions zsh-autosuggestions django npm zsh-interactive-cd zsh-navigation-tools)
Now there are 2 issues that i am trying to solve
See the , I have written the command uptil aws cognito-i and remaining is appearing as autosuggestion. the problem is that with my setup (probably theme but i have tried multiple themes) i am unable to distinguish between the command that i have typed and the command is being suggested. normally suggested command should appear a little dimmer but its the same color/opacity as the one that i have written. how to fix this
The second issue is that whenever i run a command with aws cli (also with aws-nuke, the response is opened with a new vi type window, i.e., the commands get removed and i see blank window with each line starting with ~ and at the end of the window it says END. Why is it happening and how to fix this as well
To fix the first issue try moving zsh-syntax-highlighting to the very end of plugins. From zsh-syntax-highlighting FAQ:
Why must zsh-syntax-highlighting.zsh be sourced at the end of the .zshrc file?
zsh-syntax-highlighting.zsh wraps ZLE widgets. It must be sourced
after all custom widgets have been created (i.e., after all zle -N
calls and after running compinit). Widgets created later will work,
but will not update the syntax highlighting.
To fix the second issue add the following at the end of ~/.zshrc:
# Use `less` as pager in Zsh.
READNULLCMD=less
# Use `less` as pager in external commands.
export PAGER=less
# This affects every invocation of `less`.
#
# -i case-insensitive search unless search string contains uppercase letters
# -R color
# -F exit if there is less than one page of content
# -X keep content on screen after exit
# -M show more info at the bottom prompt line
# -x4 tabs are 4 instead of 8
export LESS=-iRFXMx4
Related
I often find myself appending --help|less to commands that I am crafting a command in a shell to explore the CLI of the program I am using. What ways are there to accomplish the same thing with fewer key-presses?
For instance, if I wanted to use the new way of switching branches (I don't, I'm stuck in my ways happily doing git checkout -b other_branch) then my history (and thought process) could look like
git change other_branch # Guess what the command should be
git --help|less # Backtrack to where I am confident I know the command and ask for help
git switch --help|less # Gradually build up the command from there
git switch other_branch
For context:
I typically want the pager either to be able to search or because I am working in tmux and activating scrolling takes a few additional, and awkward, key-presses.
I typically use zsh on Ubuntu or Debian.
I typically use arrow up to iterate on my previous command.
Add the following to your .zshrc file:
# Alt-H: Open `man` page of current command.
unalias run-help
autoload -Uz run-help{,-{git,ip,openssl,p4,sudo,svk,svn}}
Then restart your shell.
Now, whenever you're in the middle of typing a command, you can press AltH (^[h) to immediately open the man page for that command. Then, after you quit your pager, Zsh will will automatically restore your command line, so you can finish typing.
When using iTerm2, every time I open it or open a new window, a 1 automatically appears in the input field and in the "last login" string above it. In the last login string, it appears before "Last login" when I first open iTerm, but appears as 1% on a new line when I open a new window.
I use the latest iTerm (3.3.7), as well as oh-my-zsh. I don't have anything defined as a command to run at the start of a session in iTerm's preferences. Up until this last update, I was able to keep the dreaded "1" from appearing by adding prompt_context () { } to my .zshrc file — but even that doesn't seem to help anymore. That said, if I completely delete the .zshrc file, the problem still persists.
Here's my current .zshrc file (minus a bunch of auto-generated, commented out lines):
ZSHING_PLUGINS=(
"https://gitlab.com/zakariaGatter/zshing"
)
# source zshing plugin
source $HOME/.zshing/zshing/zshing.zsh
# Path to your oh-my-zsh installation.
export ZSH="/Users/dc/.oh-my-zsh"
ZSH_THEME=powerlevel10k/powerlevel10k
# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"POWERLEVEL9K_MODE='nerdfont-complete'
source ~/powerlevel9k/powerlevel9k.zsh-theme
# Which plugins would you like to load?
# Standard plugins can be found in ~/.oh-my-zsh/plugins/*
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(
git
git-flow-completion
zsh-syntax-highlighting
zsh-autosuggestions
)
source $ZSH/oh-my-zsh.sh
# User configuration
export EDITOR="/usr/local/bin/atom --wait"
source /usr/local/share/chruby/chruby.sh
source /usr/local/share/chruby/auto.sh
POWERLEVEL9K_MODE='nerdfont-complete'
POWERLEVEL9K_PROMPT_ON_NEWLINE=true
POWERLEVEL9K_RPROMPT_ON_NEWLINE=true
POWERLEVEL9K_PROMPT_ADD_NEWLINE=true
POWERLEVEL9K_PROMPT_ADD_NEWLINE_COUN=4
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir vcs)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=()
POWERLEVEL9K_DISABLE_PROMPT=true
POWERLEVEL9K_PROMPT_ON_NEWLINE=true
POWERLEVEL9K_MULTILINE_LAST_PROMPT_PREFIX="▶ "
POWERLEVEL9K_MULTILINE_FIRST_PROMPT_PREFIX=""
alias ls='ls -G'
# redefine prompt_context for hiding user#hostname
prompt_context () { }
eval $(thefuck --alias)
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init -)"
fi
Here's an image of what happens when I open iTerm2 (I tried to add clear as a command to run at the start of a session to mitigate the problem via general config, but it just ended up sending 1clear instead, so that's why the autocomplete shows what it does):
https://i.gyazo.com/4c6cf3826a2da40d5a8fe225b7d030c7.png
Here's an image of what happens when I open a new iTerm2 window from an existing session: https://i.gyazo.com/06c3ce5727afe053e4f9ec2cd07c26f0.png
Here's an image of my profile's general config — I originally just put the clear in the "send text at start" option:
https://i.gyazo.com/1c3d407686047ddf1fddd957b209bef4.png
Thanks in advance to anyone who takes the time to help!
I'm not quite sure why this worked, but this fixed it:
Go to iTerm2 > Preferences > Profiles > Window
Under the "Settings for New Windows" section, change the "Space" setting from the dropdown to "Current Space"
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'm experiencing the following behaviour in bash that I find very annoying:
Type export VARIABLE=~/
Now I'd like auto-completion for the next segment of the path, so I press <tab>.
Bash clobbers the VARIABLE=, leaving just export ~/.
Why is this happening?
My bash version is 4.3.33, OS is Debian testing, terminal is Konsole.
Verify that $COMP_WORDBREAKS includes an =. If not, try this:
COMP_WORDBREAKS+==
If the export completion works to your satisfaction after that, then you need to figure out what startup file is changing COMP_WORDBREAKS.
For example, if you've installed node.js, the npm completion script (in /etc/bash_completions.d/npm removes = and # from COMP_WORDBREAKS.
Many completion scripts, somewhat annoyingly, change global settings. (For example, the standard Debian/Ubuntu completion scripts enable the extglob shell option.)
I've just moved from bash to zsh. It's a great terminal shell, but I'm missing one property - file name completion for non-standard executables.
For example, If ls gives thread_pool_examples and thread_pools:
Then typing du, space and tab would autocomplete the common prefix thread_pool, nd another click will iterate over the options:
Clicking Enter will pick the highlighted item.
The problem is that this does not work with my custom scripts. For example, if I run rmf - a Python executable in my path - and click tab, no autocomplete options will appear.
Any ideas how to make zsh autocomplete filenames for every executable?
Honestly, IMO something in your shell configuration is breaking things up. Try doing this to verify it:
zsh -f # starts a new shell ignoring your configuration
autoload compinit
compinit
./my-shell-script [TAB]
it completes with files. That is the default.
FWIW, if you want to bind a particular completer to a command/alias etc, you can do
compdef _jstack jstack
# simple _files completion
compdef _files my-local-python-script
# restrict to some file extensions
compdef '_files -g "*.(eps|ps|pdf)"' okular