commit f181429ccddbac6998b255bddcd5b47c6082e758
parent a249752711eb2cdf241c1aa433884a2d0539e13b
Author: Wim Dupont <wim@wimdupont.com>
Date: Tue, 4 Jun 2024 19:55:29 +0200
added cpp to compile commands
Diffstat:
2 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/.bashrc b/.bashrc
@@ -73,7 +73,21 @@ function nkill(){
}
function leak(){
- gcc -g "$1.c" -o "$1" && valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes -s "$1"
+ name="./$1"
+ [[ ! -f "$name" ]] && echo "$1 not found in current directory" >&2 && return 1;
+ base="${name%.*}"
+ case "${name##*.}" in
+ "c")
+ compiler=gcc
+ ;;
+ "cpp")
+ compiler=g++
+ ;;
+ *)
+ echo "Compiler not found: invalid program extension." >&2
+ return 1;
+ esac
+ $compiler -g "$name" -o "$base" && valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes -s "$base"
}
alias ls='ls --color=auto'
diff --git a/vimrc b/vimrc
@@ -76,10 +76,14 @@ autocmd BufWritePost,FileWritePost config.def.h !sudo rm config.h && sudo make i
autocmd FileType c map <F2> :w <CR> :!gcc % -o %< && ./%< <CR>
autocmd FileType c map <F3> :w <CR> :!gcc % -g -o %< && gdb ./%< <CR>
-autocmd FileType c map <F4> :w <CR> :!make && ./%< <CR>
-autocmd FileType c map <F5> :w <CR> :!make && gdb ./%< <CR>
+autocmd FileType cpp map <F2> :w <CR> :!g++ % -o %< && ./%< <CR>
+autocmd FileType cpp map <F3> :w <CR> :!g++ % -g -o %< && gdb ./%< <CR>
+autocmd FileType c,cpp map <F4> :w <CR> :!make && ./%< <CR>
+autocmd FileType c,cpp map <F5> :w <CR> :!make && gdb ./%< <CR>
autocmd FileType c :command -bar -nargs=* Run :w | :!gcc % -o %< && ./%< <args>
autocmd FileType c :command -bar -nargs=* Rund :w | :!gcc % -o %< && gdb --args ./%< <args>
-autocmd FileType c :command -bar -nargs=* Runm :w | :!make && ./%< <args>
-autocmd FileType c :command -bar -nargs=* Runmd :w | :!make && gdb --args ./%< <args>
+autocmd FileType cpp :command -bar -nargs=* Run :w | :!g++ % -o %< && ./%< <args>
+autocmd FileType cpp :command -bar -nargs=* Rund :w | :!g++ % -o %< && gdb --args ./%< <args>
+autocmd FileType c,cpp :command -bar -nargs=* Runm :w | :!make && ./%< <args>
+autocmd FileType c,cpp :command -bar -nargs=* Runmd :w | :!make && gdb --args ./%< <args>