Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 

Repository files navigation

Remove one directory level of path string in shell script

cut -d / -f 2-

$ echo a/b/c | cut -d / -f 2-
b/c

Remove first word delimited by spaces in shell script

cut -d ' ' -f 2-

$ head -1 README.md | cut -d ' ' -f 2-
Remove one directory level of path string in shell script

Match regex string in fish

string match -r

$ if string match -rq 'vim?' $EDITOR
   echo vi or vim
end
vi or vim

Slice string in fish

echo $var[1..3]

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.

Vim command that runs multiple commands

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

Source

tree do not show summary

tree --noreport

$ 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

type -q zoxide

(Using zoxide as an example)

How to make less always run with -R flag

export LESS="-R"

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

See n/name=.

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 <number>

$ printf %x 10
a

Delete a range of lines in vim ex

:6,13d

Print decimal as hex with leading zero, as necessary

printf("%02x")

$ printf %02x 15
0f

Can vim be made to accept - instead of , in range specification?

Open question #1

Why does dividing a 16-bit number by 257 convert it to 8-bit?

Open question #2

How to make dir different for 1 command in fish?

Open question #3

How to do inline parenthesized commands in fish?

Open question #4

Vim call function in key remap

nnoremap <leader>ih :call MyFunction()<cr>

link

How to open emacs with no config file

emacs -q

How to open emacs in terminal

emacs -nw

How to sleep in mysql to make an artificially slow query

select sleep(5)

About

personal how-to collection

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages