lc ~ : Displays all files in the home directory
lc ~/my-file.txt : Displays the content of my-file.txt
lc ~/my-file.txt -e : opens my-file.txt for editing using nano (you can replace with vim or anything else too)
To use, add this to your .bashrc file and refresh it # lc command
lc() {
edit=false
opts=()
paths=()
for arg in "$@"; do
case "$arg" in
-e)
edit=true
;;
-*)
opts+=("$arg")
;;
*)
paths+=("$arg")
;;
esac
done
if [ ${#paths[@]} -eq 0 ]; then
ls --color=auto "${opts[@]}"
return
fi
for p in "${paths[@]}"; do
if [ -d "$p" ]; then
ls --color=auto "${opts[@]}" "$p"
elif [ -f "$p" ]; then
if $edit; then
nano "${opts[@]}" "$p"
else
cat "${opts[@]}" "$p"
fi
else
echo "lc: $p: No such file or directory" >&2
fi
done
}
1 comments