docs: update

This commit is contained in:
Dylan Araps
2018-06-13 12:22:42 +10:00
parent 2e841bb045
commit 73e5774d04

View File

@@ -22,12 +22,12 @@ list, send a pull request!
* [Getting the terminal size (*in a script*).](#getting-the-terminal-size-in-a-script) * [Getting the terminal size (*in a script*).](#getting-the-terminal-size-in-a-script)
* [Get the current date using `strftime`.](#get-the-current-date-using-strftime) * [Get the current date using `strftime`.](#get-the-current-date-using-strftime)
* [Get the first N lines in a file.](#get-the-first-n-lines-in-a-file)
* [Get the last N lines in a file.](#get-the-last-n-lines-in-a-file)
* [Get the directory name of a file path.](#get-the-directory-name-of-a-file-path) * [Get the directory name of a file path.](#get-the-directory-name-of-a-file-path)
* [Convert a hex color to RGB](#convert-a-hex-color-to-rgb) * [Convert a hex color to RGB](#convert-a-hex-color-to-rgb)
* [Convert an RGB color to hex.](#convert-an-rgb-color-to-hex) * [Convert an RGB color to hex.](#convert-an-rgb-color-to-hex)
* [Trim quotes from a string.](#trim-quotes-from-a-string) * [Trim quotes from a string.](#trim-quotes-from-a-string)
* [Get the first N lines in a file.](#get-the-first-n-lines-in-a-file)
* [Get the last N lines in a file.](#get-the-last-n-lines-in-a-file)
<!-- vim-markdown-toc --> <!-- vim-markdown-toc -->
@@ -64,6 +64,35 @@ date() {
} }
``` ```
## Get the first N lines in a file.
Alternative to the `head` command.
**NOTE:** Requires `bash` 4+
```sh
head() {
# Usage: head "n" "file"
mapfile -tn "$1" line < "$2"
printf '%s\n' "${line[@]}"
}
```
## Get the last N lines in a file.
Alternative to the `tail` command.
**NOTE:** Requires `bash` 4+
```sh
tail() {
# Usage: tail "n" "file"
mapfile -tn 0 line < "$2"
printf '%s\n' "${line[@]: -$1}"
}
```
## Get the directory name of a file path. ## Get the directory name of a file path.
Alternative to the `dirname` command. Alternative to the `dirname` command.
@@ -106,32 +135,3 @@ trim_quotes() {
printf "%s\\n" "${_//\"}" printf "%s\\n" "${_//\"}"
} }
``` ```
## Get the first N lines in a file.
Alternative to the `head` command.
**NOTE:** Requires `bash` 4+
```sh
head() {
# Usage: head "n" "file"
mapfile -tn "$1" line < "$2"
printf '%s\n' "${line[@]}"
}
```
## Get the last N lines in a file.
Alternative to the `tail` command.
**NOTE:** Requires `bash` 4+
```sh
tail() {
# Usage: tail "n" "file"
mapfile -tn 0 line < "$2"
printf '%s\n' "${line[@]: -$1}"
}
```