From 92913578177f2cbb0d2dec9ad940fe9045a60636 Mon Sep 17 00:00:00 2001 From: Thomas Bruce Date: Sat, 1 Mar 2025 03:42:18 -0500 Subject: [PATCH] initial --- README.md | 24 ++++++++++++++++++++ compile-and-run | 16 ++++++++++++++ install.sh | 25 +++++++++++++++++++++ license.txt | 1 + projinit | 16 ++++++++++++++ tmux.conf | 42 +++++++++++++++++++++++++++++++++++ to-pdf | 54 ++++++++++++++++++++++++++++++++++++++++++++ vimrc | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 237 insertions(+) create mode 100644 README.md create mode 100755 compile-and-run create mode 100755 install.sh create mode 100644 license.txt create mode 100644 projinit create mode 100644 tmux.conf create mode 100755 to-pdf create mode 100644 vimrc diff --git a/README.md b/README.md new file mode 100644 index 0000000..74f83e6 --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# goodbye-eclipse +a minimal yet featureful vim+tmux java workflow + +made to replace eclipse for writing programs in schwartz' softdev 1 class + +## disclaimer +while the projinit script mimics eclipse's project structure, be sure to test +the project in eclipse at least the first time to verify that it is in fact +compatible. i'll be updating this to make sure that a 100% valid project is +generated for all schwartz assignments. + +## guide +make sure you have ~/.local/bin in your path + +run `projinit` to init a new project + +run `to-pdf.sh` to print the project (depends pandoc, pdflatex, eisvogel) + +run `compile-and-run.sh` to run the project like in eclipse + +because the scripts are symbolic links in each project, they barely add size to +the submission zip + +to attach to the tmux session, run `tmux a -t ge` diff --git a/compile-and-run b/compile-and-run new file mode 100755 index 0000000..a10a03c --- /dev/null +++ b/compile-and-run @@ -0,0 +1,16 @@ +#/bin/sh + +OUT="../bin" + +mkdir -p "$OUT" + +javac -d "$OUT" *.java || { echo "Compilation failed"; exit 1; } + +MAIN_CLASS=$(grep -l 'public static void main' *.java | sed 's/\.java//') + +if [ -z "$MAIN_CLASS" ]; then + echo "No main class found." + exit 1 +fi + +java -cp "$OUT" "$MAIN_CLASS" diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..ff4eb6c --- /dev/null +++ b/install.sh @@ -0,0 +1,25 @@ +#/bin/sh + +INSTALL_DIR="$HOME/.local/bin" +BACKUP_DIR="$HOME/.config/script-backups" +CONFIG_DIR="$HOME" + +mkdir -p "$INSTALL_DIR" +mkdir -p "$BACKUP_DIR" + +for file in vimrc tmux.conf; do + if [ -f "$CONFIG_DIR/$file" ]; then + mv "$CONFIG_DIR/$file" "$BACKUP_DIR/${file}.bak" + echo "backed up $file to $BACKUP_DIR/${file}.bak" + fi + cp "$file" "$CONFIG_DIR/.$file" + echo "Installed new $file" +done + +for script in to-pdf compile-and-run projinit; do + cp "$script" "$INSTALL_DIR/$script" + chmod +x "$INSTALL_DIR/$script" + echo "installed $script to $INSTALL_DIR" +done + +echo "installation complete. ensure $INSTALL_DIR is in your path" diff --git a/license.txt b/license.txt new file mode 100644 index 0000000..f944b38 --- /dev/null +++ b/license.txt @@ -0,0 +1 @@ +:) diff --git a/projinit b/projinit new file mode 100644 index 0000000..13f5c76 --- /dev/null +++ b/projinit @@ -0,0 +1,16 @@ +#!/bin/sh + +echo "enter project name: " +read project_name + +if [ -z "$project_name" ]; then + echo "err: project name cannot be empty" + exit 1 +fi + +mkdir -p "$project_name/src" "$project_name/bin" + +ln -s ~/.local/bin/to-pdf "$project_name/src/to-pdf.sh" +ln -s ~/.local/bin/compile-and-run "$project_name/src/compile-and-run.sh" + +echo "initialized project $project_name" diff --git a/tmux.conf b/tmux.conf new file mode 100644 index 0000000..bbbeff7 --- /dev/null +++ b/tmux.conf @@ -0,0 +1,42 @@ + +# use ctrl+a as the tmux prefix (instead of default ctrl+b) +set -g prefix C-a +unbind C-b +bind C-a send-prefix + +# enable mouse mode +set -g mouse on + +# improve colors +set -g default-terminal "screen-256color" + +# create or attach to "ge" session +if-shell "tmux has-session -t ge 2>/dev/null" \ + "display-message 'session ge already exists'" \ + "new-session -d -s ge -n dev 'vim -c NERDTree'" + +if-shell "tmux has-session -t ge 2>/dev/null" \ + "split-window -v -t ge:dev" + +if-shell '[ "$TMUX" = "" ]' "attach-session -t ge" + +# key bindings +bind | new-window +bind - split-window -v +bind _ split-window -h + +# resize pane shortcuts (ctrl+a then ctrl+arrow) +bind -r C-Left resize-pane -L 2 +bind -r C-Right resize-pane -R 2 +bind -r C-Up resize-pane -U 1 +bind -r C-Down resize-pane -D 1 + +# switch between panes using alt+arrow +bind -n M-Left select-pane -L +bind -n M-Right select-pane -R +bind -n M-Up select-pane -U +bind -n M-Down select-pane -D + +# switch between windows using ctrl+arrow +bind -n C-Left previous-window +bind -n C-Right next-window diff --git a/to-pdf b/to-pdf new file mode 100755 index 0000000..c3659ab --- /dev/null +++ b/to-pdf @@ -0,0 +1,54 @@ +#!/bin/sh + +echo "project name: " +read PROJECT_NAME +echo "name: " +read DEV_NAME + +OUTPUT_FILE="${PROJECT_NAME}.pdf" + +if ! command -v pandoc >/dev/null 2>&1; then + echo "err: pandoc is not installed." + exit 1 +fi + +# error checking may be nonfunctional depending on where eisvogel is installed +#if ! pandoc --template eisvogel -o /dev/null 2>/dev/null; then +# echo "err: eisvogel template is missing." +# exit 1 +#fi + +HEADER="--- +title: \"${PROJECT_NAME}\" +author: \"${DEV_NAME}\" +date: \"$(date '+%Y-%m-%d %H:%M:%S')\" +geometry: margin=1in +fontsize: 12pt +..." + +TEMP_FILE=$(mktemp) +echo "$HEADER" > "$TEMP_FILE" + +echo "appending java sources..." +for file in *.java; do + if [ -f "$file" ]; then + echo "\n\n# $file\n\n" >> "$TEMP_FILE" + echo '```java' >> "$TEMP_FILE" + cat "$file" >> "$TEMP_FILE" + echo '```' >> "$TEMP_FILE" + fi +done + +if [ -f "testdata.txt" ]; then + echo "\n\n# testdata.txt\n\n" >> "$TEMP_FILE" + echo '```' >> "$TEMP_FILE" + cat "testdata.txt" >> "$TEMP_FILE" + echo '```' >> "$TEMP_FILE" +fi + +pandoc "$TEMP_FILE" --template eisvogel -o "$OUTPUT_FILE" \ + --highlight-style tango --listings + +rm "$TEMP_FILE" + +echo "pdf generated: $OUTPUT_FILE" diff --git a/vimrc b/vimrc new file mode 100644 index 0000000..6295243 --- /dev/null +++ b/vimrc @@ -0,0 +1,59 @@ +" automatically install vim-plug if not present +if empty(glob('~/.vim/autoload/plug.vim')) + silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs \ + https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim + autocmd VimEnter * PlugInstall --sync | source $MYVIMRC +endif + +" use vim-plug to manage plugins +call plug#begin('~/.vim/plugged') + +" color scheme +Plug 'morhetz/gruvbox' + +" file explorer +Plug 'preservim/nerdtree' + +" syntax checking +Plug 'dense-analysis/ale' + +" pairing dual lexemes +Plug 'LunarWatcher/auto-pairs' +Plug 'tpope/vim-surround' + +" git wrapper +Plug 'tpope/vim-fugitive' +call plug#end() + +" basic settings +set number +set colorcolumn=80 " ruler at 80 characters +set encoding=utf-8 +set t_Co=256 " 256-colour support (st) +set background=dark +colorscheme gruvbox + +" status bar +set laststatus=2 +set showcmd +set ruler + +" autoindentation and mouse +set autoindent +set magic +set mouse=a + +" NERDTree settings +" assume leader is \ +nnoremap n :NERDTreeToggle " toggle with n +nnoremap f :NERDTreeFind " show current file f +nnoremap c :NERDTreeClose " close c + +" syntax +syntax on +filetype plugin indent on + +" ALE configurations for c and java linting and auto-format +let g:ale_linters = { 'c': ['gcc'], 'java': ['javac'] } +let g:ale_fixers = { 'c': ['clang-format'], 'java': [] } +let g:ale_c_clangformat_options = '--style={ColumnLimit: 80}' -- 2.39.5