Vifm - Jump to file in an existing instance of Vifm - client-server

Is there a way to make an existing instance of Vifm to jump to a specific file using --remote argument?

There is :goto command, which locates a path. Alternatively there is --select command-line option, but it enters directories instead of positioning cursor on them (files are handled as in :goto). Examples:
# terminal #1
vifm --server-name test
# terminal #2
vifm --server-name test --remote +'goto /etc'
vifm --server-name test --remote --select /etc/fstab

Related

Bash completion for git aliases containing multiple subcommands

I have set up the following alias in my .gitconfig file:
[alias]
ss = stash show
Unfortunately bash completion does not work correctly on this alias. When I type git ss <TAB>, I get:
❯ git ss <TAB>
apply clear drop pop show
branch create list push
Which is obviously the completion for git stash instead of git stash show.
With the original command I get the list of available stashes:
❯ git stash show <TAB>
stash#{0} stash#{1}
Is there a way to get the completion on the alias behave like on the original command?
I am on Ubuntu 20.04 and using the distro's default git completions.
I posted this question on the Git mailing list and got a reply to work around this issue:
It is possible to make completion work for your particular
alias by using our completion script's extension mechanism that allows
users to specify completion functions to their own git commands. If
you type git foo <TAB> and there is a _git_foo() function in your
shell's environment, then the completion script will invoke that
function to perform completion; this works not only for commands but
for aliases as well. So for your alias you only need to "borrow" all
the "show"-subcommand-specific case arms from _git_stash() and place
them in a _git_ss() function, e.g. like this:
_git_ss () {
case "$cur" in
--*)
__gitcomp_builtin stash_show "$__git_diff_common_options"
;;
*)
__gitcomp_nl "$(__git stash list | sed -n -e 's/:.*//p')"
;;
esac
}
Add it to your ~/.bashrc, or to a separate file that you source from
your .bashrc; If you use bash-completion, then you don't even have to
touch you .bashrc: save that function to a file git-ss (dash, not
underscore!) in one of the directories scanned by bash-completion
($BASH_COMPLETION_USER_DIR, ~/.local/share/bash-completion/completions
or its XDG_DATA_HOME-equivalent) and it will be auto-loaded as needed.

Is there a way in bash/powershell to automatically include a word in a command based on context?

Currently, when inside git repos, I type git status. Is there any way for my shell to understand this is a git repo and automatically append git to relevant commands?
e.g.,
# bash example
# before
git status
# after
status # "status" isn't a registered command, but "git status" is, so bash uses the latter
I'd probably only want this enabled when I'm in a repo, but is there any way to get functionality similar to this in any of the popular shells?
I recognize this isn't always preferred or the best idea, but it could save me from typing a word.
This is what aliases were invented for in bash. You'd add a line to your bashrc that looked like this:
alias status='git status'
If you'd like, you could add one for every git subcommand you ran frequently:
alias commit='git commit'
alias checkout='git checkout'
alias add='git add'
alias push='git push'
alias pull='git pull'
alias config='git config'
Your environment is your own, and if you wanna make a shorthand for git commands, you're free to do so!
Also, these aliases will pass any arguments to the underlying command. So if you write:
commit -m "My message"
This will translate to git commit -m "My message".
These aliases should be added to a file like the .bashrc file in your home directory, if one exists.
See here for a more in-depth explanation of aliases.

How to quickly show program help in pager

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.

iTerm2 opens command response in vi like window

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

How to use .bashrc properly and run application?

I'm trying to create an alias for an application for easy access rather than going to the directory and running it.
alias cpanel-run='"$(cd /home/ian/projects/electron/cpanel-linux-x64/)" "$(cpanel)"'
but it only displays
bash: ./cpanel: No such file or directory
Command '' not found, but can be installed with:
sudo apt install bpfcc-tools # version 0.8.0-4, or
sudo apt install mailutils-mh # version 1:3.5-2build1
sudo apt install mmh # version 0.4-2
sudo apt install nmh # version 1.7.1-4
Do you actually need to be in the same directory as the executable? If not, just do this:
alias cpanel-run='/home/ian/projects/electron/cpanel-linux-x64/cpanel'
If you do need to be in the same directory, use this instead:
alias cpanel-run='cd /home/ian/projects/electron/cpanel-linux-x64/ && ./cpanel'
(The && tells the shell to run the first (cd) command, and then run the second only if that succeeds.)
The reason your original version didn't work is that you're using $() inappropriately. What $() does is run its contents as a subprocess collect the output, and use that as part of the command line. So, your version runs the cd command, which successfully changes to the directory, but since it runs as a subprocess it has no effect on your shell or any other process. It also produces no output. Then the other $() tries to run cpanel (is it actually ./cpanel?) in a different subprocess, fails because it's not there (producing the first error message), and also produces no output. Then, based on the (empty) output from those two subprocesses, the shell tries to run the command "" "", which fails because the empty string is not a valid command.
Please refer below, I used to like this, and if you need to run open a terminal and just type kibana or elasticsearch whatever the alias name.
Please note you have to put these lines bottom of the .bashrc file
alias kibana='cd /home/bhanuka/Apps/ELK/kibana-7.5.2-linux-x86_64/bin/ && ./kibana'
alias elasticsearch='cd /home/bhanuka/Apps/ELK/elasticsearch-7.5.2-linux-x86_64/elasticsearch-7.5.2/bin/ && ./elasticsearch'
alias logstash='cd /home/bhanuka/Apps/ELK/logstash-7.5.2/bin/ && ./logstash'
alias filebeat='cd /home/bhanuka/Apps/ELK/filebeat-7.5.2-linux-x86_64/ && ./filebeat -e'

Resources