Remove one directory level of path string in shell script
$ echo a/b/c | cut -d / -f 2-
b/c
Remove first word delimited by spaces in shell script
$ head -1 README.md | cut -d ' ' -f 2-
Remove one directory level of path string in shell script
Match regex string in fish
$ if string match -rq 'vim?' $EDITOR
echo vi or vim
end
vi or vim
Slice string in fish
Called "index range expansion". Works on whole lines.
Since fish 3.2 the end index is optional.
$ echo (seq 3)[2..]
2 3
To slice within a line, use string split ' '
first.
$ echo (echo a b c | string split ' ')[2..]
b c
Move a directory into the current directory, overwriting a local directory of the same name
rsync --archive --delete <source> <destination>
The issue arises in the following directory structure:
$ tree
.
├── dir-a
│ └── dir-b
│ └── some_file
└── dir-b
└── useless_file
3 directories, 2 files
# mv errors instead of overwriting dir-b
$ mv dir-a/dir-b/ .
mv: rename dir-a/dir-b/ to ./dir-b/: Directory not empty
# explicitly passing ./dir-b just puts the files in ./dir-b, creating a nested dir-b:
$ mv dir-a/dir-b/ ./dir-b
$ tree
.
├── dir-a
└── dir-b
├── dir-b
│ └── some_file
└── useless_file
3 directories, 2 files
Vim search for whole word
/\<word\>
(though starting with < is usually enough)
This is so that for example eat
isn't found in create
.
command
that runs multiple commands
Vim Tell the first that it can be followed with another using -bar
:
command! -bar Terminal terminal
Then create a command that uses |
to run multiple commands:
command! FullscreenTerminal Terminal|:only
tree
do not show summary
$ tree --noreport
.
└── dir
└── some_file
funcsave
to current directory
funcsave -d .
(from man funcsave
)
$ function commit
git-add-commit (echo (cat README.md | grep '###' | tail -1 | string split ' ')[2..])
end
$ funcsave -d . commit
$ git stat
## main...origin/main
?? commit.fish
Github website submit comment and close issue
⌘ shift enter
How to make fish script executable
Start with #!/usr/bin/env fish
Check if argument is executable in fish
(Using zoxide as an example)
less
always run with -R
flag
How to make
How to parse and access named arguments with fish
$ function arg_test
argparse d/directory= -- $argv
echo $_flag_directory
end
$ arg_test -d 3
3
n/name=
means that both-n
and--name
are valid. It requires a value and can be used at most once. If the flag is seen then_flag_n
and_flag_name
will be set with the single mandatory value associated with the flag.
How to show git diff inline, by words
git diff --color-words
Decimal to hex in shell
$ printf %x 10
a
Delete a range of lines in vim ex
Print decimal as hex with leading zero, as necessary
$ printf %02x 15
0f
-
instead of ,
in range specification?
Can vim be made to accept
Why does dividing a 16-bit number by 257 convert it to 8-bit?
How to make dir different for 1 command in fish?
How to do inline parenthesized commands in fish?
Vim call function in key remap
nnoremap <leader>ih :call MyFunction()<cr>