Can I use Bash autocompletions for kubectl in fish? - kubectl

Does anybody use fish shell with Kubectl commands? This Bash completion
source <(kubectl completion bash | sed 's/kubectl/k/g')
works like dizzying charm for Bash. But how to do that same thing in fish shell?

Fish is not generally compatible with bash, and bash's completion system is quite different from fish's. It's possible to jerry-rig some of it (if a tool takes $COMP_CWORD and such), but the real solution is to use a completion script written for fish, like https://github.com/evanlucas/fish-kubectl-completions.
There was also some work to integrate fish completions upstream, but that has seemingly stalled.

In Fish this would easiest be solved with an abbreviation. Running abbr --add --global k kubectl will permanently add an abbreviation k that gets replaced with kubectl when you press space/enter. After the auto-replacement, any existing autocompletions you already have installed for kubectl will work as normal. (See the official docs for installing kubectl autocompletions if you don't have them already.)
Abbrevations in fish can replace use-cases that many other shells use aliases for, but still allow editing the command line in case you want to tweak something manually. For example, I have a fish port of the common kubectl-aliases that adds the shortcuts as abbreviations.

Related

What does it mean by the last dash in $(gcc -xc++ -E -v -)? [duplicate]

Examples:
Create an ISO image and burn it directly to a CD.
mkisofs -V Photos -r /home/vivek/photos | cdrecord -v dev=/dev/dvdrw -
Change to the previous directory.
cd -
Listen on port 12345 and untar data sent to it.
nc -l -p 12345 | tar xvzf -
What is the purpose of the dash and how do I use it?
If you mean the naked - at the end of the tar command, that's common on many commands that want to use a file.
It allows you to specify standard input or output rather than an actual file name.
That's the case for your first and third example. For example, the cdrecord command is taking standard input (the ISO image stream produced by mkisofs) and writing it directly to /dev/dvdrw.
With the cd command, every time you change directory, it stores the directory you came from. If you do cd with the special - "directory name", it uses that remembered directory instead of a real one. You can easily switch between two directories quite quickly by using that.
Other commands may treat - as a different special value.
It's not magic. Some commands interpret - as the user wanting to read from stdin or write to stdout; there is nothing special about it to the shell.
- means exactly what each command wants it to mean. There are several common conventions, and you've seen examples of most of them in other answers, but none of them are 100% universal.
There is nothing magic about the - character as far as the shell is concerned (except that the shell itself, and some of its built-in commands like cd and echo, use it in conventional ways). Some characters, like \, ', and ", are "magical", having special meanings wherever they appear. These are "shell metacharacters". - is not like that.
To see how a given command uses -, read the documentation for that command.
It means to use the program's standard input stream.
In the case of cd, it means something different: change to the prior working directory.
The magic is in the convention. For millennia, people have used '-' to distinguish options from arguments, and have used '-' in a filename to mean either stdin or stdout, as appropriate. Do not underestimate the power of convention!

search both history log and files on git, with termux and regexp

tried every answer from similar questions:
How to grep Git commit diffs or contents for a certain word?
Search all of Git history for a string?
How to grep (search) committed code in the Git history
none worked!
would it even be possible to search using anything other than git itself?
repository tested: http://cregox.net
scenario
picture hundreds of markdown files, a dozens of which will have something like this:
---
title: lorem ipsum
description: foo, or not foo, it's not even a question
bar: false
(in practice, instead of foo it was checklist and instead of bar i wanted published)
expected
ag "foo[\s\S]*bar:\ "
will search all files with 1 foo that happens before the first bar: if they both exist.
all i needed was that, applied to git history.
that's it.
but...
reality
git log -G "foo[\s\S]*bar:\ "
instead of silversearcher-ag doesn't even work because of \s.
i've tried many variations of regexp, couldn't find any single one that would work!
so that's something that i'll want to fix at some point, but meanwhile i also tried other alternatives...
git log -p -S foo
should bring something similar to rg foo, but doesn't come even close to be readable and it's way too verbose.
git log --name-status --oneline -S foo
this was the closest i could get to the expected results... but it's still too cumbersome.
i give up digging for now.
With git log regex following should work for you to match across the lines:
git log --name-status --oneline -G 'foo(\S|\s)+bar:\s'

Using regex and pscp on AIX servers

I've been having lots of troubles using pscp and regex on AIX server.
As you can see, I am trying to use Putty's pscp to transfer file "stdout" to my local folder.
This usually works fine, but my problem is that I won't know exact same folder name so I need to use REGEX.
I've been told that possibly my regex was written for grep and that it wasn't supported by pscp.
What would be alternative then to write regex for pscp.
Error message is: "multiple-level wildcards unsupported"
pscp.exe -P 22 -pw krt_345 testuser#testserver5:"/app/log/s500/20201023/.\*/20201023-02\.2[0-9]\.[0-5][0-9]_s500_testuser.\*"/stdout C:\logs
regex only:
"/app/log/s500/20201023/.\*/20201023-02\.2[0-9]\.[0-5][0-9]_s500_testuser.\*"/stdout
With SCP protocol, the filemask in the path is resolved by the server. With a typical OpenSSH scp "server", you can use standard Linux glob masks. Definitely not regex. Though your mask is simple enough, that a simple glob mask 20201023-02.2[0-9].[0-5][0-9]_s500_testuser* would. But you can use glob mask for the last path component only. Not for the parent directory. What is what the "multiple-level wildcards unsupported" error message is trying to tell you.
So what you are doing is not doable with SCP. You would have to obtain the folder name using other means. Like using a shell commands over SSH.
And I belive you have asked for this already:
Finding folder name on a server using batch file
And based on your comments to the answer, you already know what you need to combine a shell command like find with scp. So I do not understand, why don't you ask for that.

Timed Shutdown Using Visudo

I am wanting to grant user user01 on my machine the ability to shut down the machine, but only with no less than 1 hour notice.
Essentially, this boils down to the following command:
shutdown -h +<time>
In this case, <time> must be greater than 60 (minutes).
Using visudo, I added the following sudoers line:
user01 ALL=/sbin/shutdown -h +<time>
I need some way to ensure that user01 may only issue the halt shutdown if the time argument is greater than 60. I've tried regex, but to no avail. I may be wrong in saying this, but it appears that the sudoers file may not support regex?
Any help with regards to evaluating an expression to achieve this task would be appreciated.
I don't even want to know if sudoers has regex support (a quick grep suggests it doesn't):
Regexes are tricky, a simple mistake could allow a user to run Elvis-knows-what...
[6-9][0-9]|[1-9][0-9]*[0-9][0-9] - you could shorten it if the notation allows shortcuts for counting occurrences (or just use a '+'), but would you really want it?
That being said, imho the easiest (and most sensible) solution is to write a script along the lines of
#! /bin/sh
test $# -eq 1 || exit
test 60 -lt "$1" || exit # maybe print a message
exec /sbin/shutdown -h "+$1"
and allow user01 to sudo that script.

How to get the list of all installed color schemes in Vim?

Is there a way to get a list of all installed color schemes in Vim? That would make very easy to select one without looking at the .vim directory.
Type
:colorscheme then Space followed by TAB.
or as Peter said,
:colorscheme then Space followed by CTRLd
The short version of the command is :colo so you can use it in the two previous commands, instead of using the "long form".
Just for convenient reference as I see that there are a lot of people searching for this topic and are too laz... sorry, busy, to check for themselves (including me). Here is a list of the default set of colour schemes for Vim 7.4:
blue.vim
darkblue.vim,
delek.vim
desert.vim
elflord.vim
evening.vim
industry.vim
koehler.vim
morning.vim
murphy.vim
pablo.vim
peachpuff.vim
ron.vim
shine.vim
slate.vim
torte.vim
zellner.vim
You can see the list of color schemes under /usr/share/vim/vimNN/colors (with NN being the version, e.g. vim74 for vim 7.4).
This is explained here.
On the linux servers I use via ssh, TAB prints ^I and CTRLd prints ^D.
If you are willing to install a plugin, I recommend https://github.com/vim-scripts/CycleColor.
to cycle through all installed colorschemes. Nice way to easily choose a colorscheme.
Looking at my system's menu.vim (look for 'Color Scheme submenu') and #chappar's answer, I came up with the following function:
" Returns the list of available color schemes
function! GetColorSchemes()
return uniq(sort(map(
\ globpath(&runtimepath, "colors/*.vim", 0, 1),
\ 'fnamemodify(v:val, ":t:r")'
\)))
endfunction
It does the following:
Gets the list of available color scheme scripts under all runtime
paths (globpath, runtimepath)
Maps the script paths to their base names (strips parent dirs and
extension) (map, fnamemodify)
Sorts and removes duplicates (uniq, sort)
Then to use the function I do something like this:
let s:schemes = GetColorSchemes()
if index(s:schemes, 'solarized') >= 0
colorscheme solarized
elseif index(s:schemes, 'darkblue') >= 0
colorscheme darkblue
endif
Which means I prefer the 'solarized' and then the 'darkblue' schemes; if none of them is available, do nothing.
Here is a small function I wrote to try all the colorschemes in $VIMRUNTIME/colors directory.
Add the below function to your vimrc, then open your source file and call the function from command.
function! DisplayColorSchemes()
let currDir = getcwd()
exec "cd $VIMRUNTIME/colors"
for myCol in split(glob("*"), '\n')
if myCol =~ '\.vim'
let mycol = substitute(myCol, '\.vim', '', '')
exec "colorscheme " . mycol
exec "redraw!"
echo "colorscheme = ". myCol
sleep 2
endif
endfor
exec "cd " . currDir
endfunction
If you have your vim compiled with +menu, you can follow menus with the :help of console-menu. From there, you can navigate to Edit.Color\ Scheme to get the same list as with in gvim.
Other method is to use a cool script ScrollColors that previews the colorschemes while you scroll the schemes with j/k.
i know i am late for this answer but the correct answer seems to be
See :help getcompletion():
:echo getcompletion('', 'color')
which you can assign to a variable:
:let foo = getcompletion('', 'color')
or use in an expression register:
:put=getcompletion('', 'color')
This is not my answer, this solution is provided by u/romainl in this post on reddit.
A great solution, and my thanks to your contributors. For years I've been struggling with a totally crappy color scheme -- using SSH under Windows Vista to a Redhat system, terminal type xterm.
The editor would come up with a black background and weird colors for various keywords.
Worse -- that weird color scheme sticks in the xterm terminal after leaving Vim.
Really confusing.
Also, Backspace failed during an insert mode, which was nasty to remember -- though Delete did the same thing.
The cure --
In the SSH monitor, select Edit/Settings.
a. Choose Profile Settings/Colors
b. check 'enable ANSI colors'
c. The standard Text colors are probably OK
Add these lines to $HOME/.vimrc:
colorscheme default
if &term == "xterm"
set t_kb=^H
fixdel
endif
NOTE: the ^H MUST be typed as ctrl-V ctrl-H. Seems peculiar, but this seems to work.
Try
set wildmenu
set wildmode=list:full
set wildcharm=<C-z>
let mapleader=','
nnoremap <leader>c :colorscheme <C-z><S-Tab>
in your ~/.vimrc.
The first two lines make possible matches appear as lists. You can use either or both.
The fourth line makes leader , instead of the default \.
The last line allows you to simply type ,c to get a list and a prompt to change your colorscheme.
The third line effectively allows for Tabs to appear in key maps.
(Of course, all of these strategies I've learned from the internet, and mostly SO, very recently.)
Another simpler way is while you are editing a file - tabe ~/.vim/colors/ ENTER
Will open all the themes in a new tab within vim window.
You may come back to the file you were editing using - CTRL + W + W ENTER
Note: Above will work ONLY IF YOU HAVE a .vim/colors directory within your home directory for current $USER
(I have 70+ themes)
[user#host ~]$ ls -l ~/.vim/colors | wc -l
72