Is there a way in the Fish Interactive shell for the full path to be displayed. Currently when I navigate to a directory I get the following shell.
millermj#Dodore ~/o/workspace
but I would rather see
millermj#Dodore ~/o-town/workspace
With the new fishshell (v2.3) you can do set -U fish_prompt_pwd_dir_length 0. And it will use the full path. I also use dartfish for my theme. See example below:
Here's my version of prompt_pwd that should display what you're looking for:
function prompt_pwd --description 'Print the current working directory, NOT shortened to fit the prompt'
if test "$PWD" != "$HOME"
printf "%s" (echo $PWD|sed -e 's|/private||' -e "s|^$HOME|~|")
else
echo '~'
end
end
This will display the tilde for the home directory, as usual, but removes the sed command that only pulls the first letter from each directory when you're a few directories deep.
To edit prompt_pwd use funced. It will allow you to interactively alter the function. From the command line type funced prompt_pwd. Once the prompt is displaying to your liking, use funcsave prompt_pwd to make the behavior persist in future sessions.
I personally don't like touching the shared/defaults. Fish has a great functions design, so leverage that.
Create ~/.config/fish/functions/prompt_long_pwd.fish with the contents:
function prompt_long_pwd --description 'Print the current working directory'
echo $PWD | sed -e "s|^$HOME|~|" -e 's|^/private||'
end
Then simply edit your ~/.config/fish/functions/fish_prompt.fish to use prompt_long_pwd. Here is the custom prompt that I use:
~/.config/fish/config.fish:
set -g __fish_git_prompt_show_informative_status 1
set -g __fish_git_prompt_hide_untrackedfiles 1
set -g __fish_git_prompt_color_branch magenta bold
set -g __fish_git_prompt_showupstream "informative"
set -g __fish_git_prompt_char_upstream_ahead "↑"
set -g __fish_git_prompt_char_upstream_behind "↓"
set -g __fish_git_prompt_char_upstream_prefix ""
set -g __fish_git_prompt_char_stagedstate "●"
set -g __fish_git_prompt_char_dirtystate "✚"
set -g __fish_git_prompt_char_untrackedfiles "…"
set -g __fish_git_prompt_char_conflictedstate "✖"
set -g __fish_git_prompt_char_cleanstate "✔"
set -g __fish_git_prompt_color_dirtystate blue
set -g __fish_git_prompt_color_stagedstate yellow
set -g __fish_git_prompt_color_invalidstate red
set -g __fish_git_prompt_color_untrackedfiles $fish_color_normal
set -g __fish_git_prompt_color_cleanstate green bold
~/.config/fish/functions/fish_prompt.fish
function fish_prompt --description 'Write out the prompt'
set -l last_status $status
if not set -q __fish_prompt_normal
set -g __fish_prompt_normal (set_color normal)
end
# PWD
set_color $fish_color_cwd
echo -n (prompt_long_pwd)
set_color normal
printf '%s ' (__fish_git_prompt)
if not test $last_status -eq 0
set_color $fish_color_error
end
echo -n '$ '
end
Create ~/.config/fish/functions/prompt_long_pwd.fish with:
function prompt_long_pwd --description 'Print the full working directory'
echo $PWD
end
In ~/.config/fish/functions/fish_prompt.fish change (prompt_pwd) (set_color normal) to (prompt_long_pwd) (set_color normal).
(prompt_pwd) replaces the directory name with the first letter of the directory, which I too sometimes find annoying. You can also probably modify the original command prompt_pwd, I have not tried it.
This answer is modified from the earlier answer and shows the full directory while keeping the other parts of the default prompt. The key change is in the expression in ~/.config/fish/functions/prompt_long_pwd.fish.
Just thought I'd give everyone a heads up if you stumbled on this and your fish is not responding to the fish_prompt_pwd_dir_length variable try upgrading omf, and then update your omf themes that you're using. Then do some combination of selecting a different theme, reopening the shell, and selecting a different theme again. This is what worked for me. Good luck!
The prompt_pwd function determines the function to be displayed. You should be able to write your own version to get what you want.
Related
Related: Here, Here, Here, & Here.
I want to be able to use gui applications with ranger, e.g., I want to click a desktop folder icon & have it open in ranger.
Steps I take & errors that follow:
Set /home/ertecturing/.scripts/Ranger_Default_File_Manager.sh "%s" as default file manager in xfce settings
Ranger_Default_File_Manager.sh runs
xfce4-terminal -T "Ranger File Manager" -x ranger $#
This commands almost works, but it creates a directory error because directories given by $# always start with only file:/// not file://// like they need to in order to function.
I tried to add the missing 4th slash with this sed command someone shared with me:
OUT=$(sed -e 's/\/\/\//\/\/\/\//g' $1)
xfce4-terminal -T "Ranger File Manager" -x ranger $OUT
I have little idea whether that first line's syntax is correct.
The first line only produces blank output, but if I test a similar command echo $# | sed "s/\/\/\//\/\/\/\//g" >> ~/Desktop/file it always outputs the 4th slash I'm looking for.
Does anyone know a way to solve this issue? Help is highly appreciated.
Changing your OUT variable to the command that you say works may be a better approach.
OUT=$(echo "$#" | sed 's|$|/|g')
Additional Solution for Spaces:
OUT=$(echo "$#" | sed "s:///:////:g" | sed "s/%20/ /g")
xfce4-terminal -T "Ranger File Manager" -x ranger "$OUT"
How can I get make to not print flags.
Example:
prettycolors:
#echo -e "\e[32mIM GREEN\e[0m"
Current behavior:
$ make prettycolors
-e IM GREEN
Desired behavior:
$ make prettycolors
IM GREEN
Seems like shell does not accept echo flags.
You can either specify echo you want to use: (in Makefile)
ECHO=/bin/echo
prettycolors:
#$(ECHO) -e "\e[32mIM GREEN\e[0m"
or specify "smarter" shell:
$ make SHELL=/bin/bash prettycolors
I'm a Windows user with the Git Bash shell as my daily-driver. I'm curious how the __git_ps1 function updates the prompt every time you change a directory. It's really the only example of updating the bash prompt on the fly that I've seen. I want to leverage this behavior in my own function to add a display on my prompt if I have an RDP session open.
tldr: Any ideas on how the __git_ps1 function evaluates the bash prompt on the fly????
So here is my simple function to see if the RDP client is running
function __rdp_ps1() {
local MATCH=
if tasklist | grep --quiet mstsc; then
MATCH="\e[41mRDP\e[0m"
fi
echo "$MATCH"
}
So the idea is I want to display RDP with a red background, and I want my shell to evaluate this on the fly the same way __git__ps1 is seemingly able to.
What I've investigated (without real success) so far
/etc/profile.d/git-prompt.sh
This block seems to create the PS1 my shell is using
PS1='\[\033]0;$TITLEPREFIX:$PWD\007\]' # set window title
PS1="$PS1"'\n' # new line
PS1="$PS1"'\[\033[32m\]' # change to green
PS1="$PS1"'\u#\h ' # user#host<space>
PS1="$PS1"'\[\033[35m\]' # change to purple
PS1="$PS1"'$MSYSTEM ' # show MSYSTEM
PS1="$PS1"'\[\033[33m\]' # change to brownish yellow
PS1="$PS1"'\w' # current working directory
if test -z "$WINELOADERNOEXEC"
then
GIT_EXEC_PATH="$(git --exec-path 2>/dev/null)"
COMPLETION_PATH="${GIT_EXEC_PATH%/libexec/git-core}"
COMPLETION_PATH="${COMPLETION_PATH%/lib/git-core}"
COMPLETION_PATH="$COMPLETION_PATH/share/git/completion"
if test -f "$COMPLETION_PATH/git-prompt.sh"
then
. "$COMPLETION_PATH/git-completion.bash"
. "$COMPLETION_PATH/git-prompt.sh"
PS1="$PS1"'\[\033[36m\]' # change color to cyan
# tried hamjamming PS1="$PS1 `__rdp_ps1`" here, it only works on login
PS1="$PS1"'`__git_ps1`' # bash function
fi
fi
PS1="$PS1"'\[\033[0m\]' # change color
PS1="$PS1"'\n' # new line
PS1="$PS1"'$ ' # prompt: always $
So I went to see where this file was being sourced to see if that could lead to the answer
/etc/bash.bashrc
Last line held the gold
# Fixup git-bash in non login env
shopt -q login_shell || . /etc/profile.d/git-prompt.sh`
So I evaluated shopt login_shell and it's always on, but I don't really know what that means because the comment leads me to believe that when login env is off, the prompt script will be evaluated
Any ideas???
Your problem might be that you define your $PS1 with double quotes, which bash interprets when executing. Which means that __rdp_ps1 is ran when $PS1 is defined.
In your .bashrc, try replacing the definition with:
PS1='$PS1 `__rdp_ps1`' # Note the single quote.
I have a similar feature on my PS1 (but to display the number of jobs in the background), here is the full version (available here: https://github.com/padawin/dotfiles/blob/master/.bashrc#L70):
function j(){
jobs | wc -l | egrep -v ^0 | sed -r 's/^([0-9]+)/ (\1)/'
}
PROMPT_COMMAND=__prompt_command # Func to gen PS1 after CMDs
__prompt_command() {
local EXIT="$?" # This needs to be first
PS1="$(virtual_env_name)"
local RCol='\[\e[0m\]'
local Red='\e[0;31m'
local Gre='\e[0;32m'
local Blu='\e[1;34m'
PS1+="${Gre}\u#\h$(j)${RCol}: ${Red}\w${Blu}$(__git_ps1)"
if [ $EXIT != 0 ]; then
PS1+="$Red \342\234\226 (${EXIT})"
else
PS1+="$Gre \342\234\224"
fi
PS1+="$RCol\n> "
}
Which can be simplified as the following in .bashrc:
function j(){
jobs | wc -l | egrep -v ^0 | sed -r 's/^([0-9]+)/ (\1)/'
}
PS1='\u$(j) > ' # Note the single quote here
Which behaves as follow:
padawin > vim
[1]+ Stopped vim
padawin (1) > fg
vim
padawin >
Not directly a solution but this might help: if you want to know where the __git_ps1 function lives locally on your filesystem so you can experiment with making edits, you can do
grep -r __git_ps1 /
which searches for the string '__git_ps1' across the file contents of git bash's entire filesystem (where / is actually C:\Program Files\Git or wherever you have it installed).
For me, it was at /mingw64/share/git/completion/git-prompt.sh
My use case was removing the parenthesis from the branch name, which I did by changing this line:
local printf_format=' (%s)'
in the __git_ps1 () function
What you are looking for is PROMPT_COMMAND. Bash will execute whatever is in there before displaying a prompt. If your PS1 is being updated on-the-fly, you probably already have a PROMPT_COMMAND.
I want fish shell to show full path in prompt. Looking at source of pwd_prompt I see a variable named fish_prompt_pwd_dir_length, that should do what I want if I set it to 0.
But when I do set -U fish_prompt_pwd_dir_length 0 nothing happens.
Looking in fish_config variables tab I see that this var is set to 0, but still path shown reduced.
What am I doing wrong and can you actually do that without writing your own pwd_prompt function?
UPD (June 20, 2016):
Since version 2.3.0 (which is now recent) all is working as expected
Previous answer:
My workaround so far is to copy prompt_pwd into new function prompt_pwd_full and mess with it a little bit.
prompt_pwd_full.fish:
set -l args_pre
set args_pre $args_pre -e 's|^/private/|/|'
function prompt_pwd_full -V args_pre
set -q fish_prompt_pwd_dir_length; or set -l fish_prompt_pwd_dir_length 1
if [ $fish_prompt_pwd_dir_length -eq 0 ]
set -l fish_prompt_pwd_dir_length 99999
end
set -l realhome ~
echo $PWD | sed -e "s|^$realhome|~|" $args_pre -e 's-\([^/.]{'"$fish_prompt_pwd_dir_length"'}\)[^/]*/-\1/-g'
end
note: I am on OS X, so I threw out a bunch of code that wasn’t related to it, so it might not work in other OS’es.
UPD:
As faho noted in the comment, there is no particular reason to rewrite /private/ to /, so my function is looking like this now:
function prompt_pwd_full
set -q fish_prompt_pwd_dir_length; or set -l fish_prompt_pwd_dir_length 1
if [ $fish_prompt_pwd_dir_length -eq 0 ]
set -l fish_prompt_pwd_dir_length 99999
end
set -l realhome ~
echo $PWD | sed -e "s|^$realhome|~|" -e 's-\([^/.]{'"$fish_prompt_pwd_dir_length"'}\)[^/]*/-\1/-g'
end
Adding set -g fish_prompt_pwd_dir_length 80 to ~/.config/fish/config.fish works for me. My fish version is 3.0.2
I want to change the title everytime I enter a new directory ( when using cd ), but show only the last 2 directories. I'm using tcsh at work and bash at home.
For example: if I'm at folder ~/work/stuff and I write: cd 1.1, I want my new title to be stuff/1.1.
I already know how to change the title everytime I change the folder:
alias cd 'cd \!*; echo "\033]0;`pwd`\a"'
And I know how to take only the 2 last directories:
pwd | awk -F / -v q="/" '{print $(NF-1)q$NF}'
The question is how to combine these two, or how to do it in a different way?
It doesn't have to be through alias to cd.
What I did was creating a script file named titleRename.tcsh with the following code:
#!/bin/tcsh -f
set fullpath = "`pwd`\a"
set newTitle = `echo $fullpath | awk -F / '{OFS="/"; if(NF > 2){printf $(NF-2);printf "/"; printf $(NF-1); printf "/"; print $NF;}else print $0}'`
echo "\033]0;$newTitle"
It splits the pwd with awk, getting only the last 3 directories, and then it prints to the tab name.
Then I added in the .alias file the following:
alias cd 'cd \!*; <dir of script file>/titleRename.tcsh'
Now the title name changes automatically whenever I cd to a different directory :)
I originally thought you should be able to use the full command where you have pwd in backticks in the alias ie:
alias cd 'cd \!*; echo "\033]0;`pwd | awk -F / -v q="/" '{print $(NF-1)q$NF}'`\a"'
but now I realise there may be problems with the nested quoting. And that wouldn't work in bash anyway; I don't think there's a way to access command parameters in an alias.
Instead of aliasing cd you should update the title with the prompt. I don't know tcsh, but in bash the normal way to do this sort of thing is with the special pseudo-variable PS1:
# Minimalist prompt
PS1="\$ "
# Additionally set terminal title to cwd
case "$TERM" in
xterm*|rxvt*)
PROMPT_DIRTRIM=2
PS1="\033]0;\w\a$PS1"
;;
*)
;;
esac
That won't trim the directory name quite the way you were doing it, but unfortunately I can't get the quoting right to be able to use the escape sequence in PROMPT_COMMAND.