mirror of
https://codeberg.org/vlw/dotfiles.git
synced 2025-11-05 01:12:42 +01:00
fix(bash): l functions not reading from the correct target dir (#50)
Reviewed-on: https://codeberg.org/vlw/dotfiles/pulls/50
This commit is contained in:
parent
d7902bc188
commit
b42d346dbb
1 changed files with 46 additions and 10 deletions
|
|
@ -15,13 +15,25 @@ alias qa="tmux split-window -v"
|
||||||
|
|
||||||
# Preview contents of a file or list the contents of a directory
|
# Preview contents of a file or list the contents of a directory
|
||||||
l () {
|
l () {
|
||||||
if [ -f "$1" ] ; then
|
# Set target to argument or default to current working directory
|
||||||
less $1
|
local target="${1:-$(pwd)}"
|
||||||
|
|
||||||
|
if [ -f $target ] ; then
|
||||||
|
less $target
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# List current directory contents and bail out if target does not exist
|
||||||
|
if [ ! -d $target ]; then
|
||||||
|
l $(dirname $target)
|
||||||
|
echo ""
|
||||||
|
echo -e "\e[0;91mNo such file or directory '$target'\e[0m"
|
||||||
|
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Current directory is the user home directory
|
# Current directory is the user home directory
|
||||||
if [ "$(pwd)" == "$HOME" ]; then
|
if [ $target == "$HOME" ]; then
|
||||||
# Ignore these files when running the "l" command from the home directory
|
# Ignore these files when running the "l" command from the home directory
|
||||||
local BLACKLIST=("Makefile")
|
local BLACKLIST=("Makefile")
|
||||||
|
|
||||||
|
|
@ -36,27 +48,51 @@ l () {
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ls -lh $1 || l $(dirname "$1")
|
ls -lh $target
|
||||||
}
|
}
|
||||||
|
|
||||||
# Preview the contents of a file or list the contents of a directory with hidden files shown
|
# Preview the contents of a file or list the contents of a directory with hidden files shown
|
||||||
ll () {
|
ll () {
|
||||||
if [ -f "$1" ] ; then
|
# Set target to argument or default to current working directory
|
||||||
less $1
|
local target="${1:-$(pwd)}"
|
||||||
|
|
||||||
|
if [ -f $target ] ; then
|
||||||
|
less $target
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ls -lah $1 || ll $(dirname "$1")
|
# List current directory contents and bail out if target does not exist
|
||||||
|
if [ ! -d $target ]; then
|
||||||
|
ll $(dirname $target)
|
||||||
|
echo ""
|
||||||
|
echo -e "\e[0;91mNo such file or directory '$target'\e[0m"
|
||||||
|
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
ls -lah $target
|
||||||
}
|
}
|
||||||
|
|
||||||
# Edit the contents of a file or list the contents of a directory (with hidden files shown) if that file is not found
|
# Edit the contents of a file or list the contents of a directory (with hidden files shown) if that file is not found
|
||||||
lll () {
|
lll () {
|
||||||
if [ -f "$1" ] ; then
|
# Set target to argument or default to current working directory
|
||||||
nano $1
|
local target="${1:-$(pwd)}"
|
||||||
|
|
||||||
|
if [ -f $target ] ; then
|
||||||
|
nano $target
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ls -lah $1 || lll $(dirname "$1")
|
# List current directory contents and bail out if target does not exist
|
||||||
|
if [ ! -d $target ]; then
|
||||||
|
lll $(dirname $target)
|
||||||
|
echo ""
|
||||||
|
echo -e "\e[0;91mNo such file or directory '$target'\e[0m"
|
||||||
|
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
ls -lah $target
|
||||||
}
|
}
|
||||||
|
|
||||||
.. () {
|
.. () {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue