zsh: changes to cdt() and cds(), and bug fix for rmswp() when the
swapfile isn't mounted
This commit is contained in:
parent
8ebfb3b8d2
commit
15fba89c84
1 changed files with 17 additions and 5 deletions
22
.zshrc
22
.zshrc
|
@ -196,20 +196,32 @@
|
|||
{
|
||||
# cd search: cd to a directory, given part of its name
|
||||
# (also can take arguments for an `fd` commnd)
|
||||
# (also can cd to a file if `-t f` is passed)
|
||||
cds() {
|
||||
if ! [ -z "$1" ];then
|
||||
cd "$(fd --max-results=1 -t d $@)" && pwd
|
||||
DIR="$(fd --max-results=1 -t d $@)"
|
||||
if [ -f "$DIR" ];then
|
||||
cd "$(dirname "$DIR")" && pwd
|
||||
else
|
||||
cd "$DIR" && pwd
|
||||
fi
|
||||
else
|
||||
echo "$0: no arguments provided"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# cd to: cd to the containing dir of a file or folder, given part of its name
|
||||
# cd find (interactive): cd to the containing dir of a file, or inside a folder, given part of its name
|
||||
# Basically, an interactive version of what's above
|
||||
# can take an `fd` command
|
||||
# requires that `fzy` is installed
|
||||
cdt() {
|
||||
cd "$(dirname "$(fd $@ | fzy)")" && pwd
|
||||
cdf() {
|
||||
DIR="$(fd $@ | fzy)"
|
||||
if [ -f "$DIR" ];then
|
||||
cd "$(dirname "$DIR")" && pwd
|
||||
else
|
||||
cd "$DIR" && pwd
|
||||
fi
|
||||
}
|
||||
|
||||
# cd all: opens a new shell in each of the directories below the one you're in, so
|
||||
|
@ -476,7 +488,7 @@
|
|||
|
||||
# Deletes the swapfile created by mkswp()
|
||||
rmswp() {
|
||||
sudo swapoff -v /swapfile &&
|
||||
sudo swapoff -v /swapfile
|
||||
sudo rm /swapfile
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue