Personal dotfiles for Linux, mostly for Nixpkgs/NixOS-based and Termux setups. Mirrored using GitLab's push mirroring feature.
gitlab.com/andreijiroh-dev/dotfiles
linux
dotfiles
1#!/bin/env bash
2
3# SPDX-License-Identifier: MPL-2.0
4# An bloody script for opening text editors from the command line via $EDITOR and
5# command flags, work in progress and probably abandoned.
6
7# shellcheck disable=SC2034
8VSCODE_PATH=$(command -v code) # TODO: Add PATH detection for VS Code Desktop+Server/OpenVSCode Server/VSCodium/code-server
9NANO_PATH=$(command -v nano)
10VI_PATH=$(command -v vi) # maybe neovim?
11OPEN_EDITOR_LOCKFILE=$HOME/.dotfiles/config/open-editor
12
13if [[ $1 == "" ]]; then
14 echo "open-editor: Want to learn more how to use me? Use the '--help' flag to see the docs."
15 exit
16fi
17
18# Stack Overflow: https://stackoverflow.com/questions/7069682/how-to-get-arguments-with-flags-in-bash#21128172
19while test $# -gt 0; do
20 case "$1" in
21 -h|--help)
22 echo "$0 - shortcut to open editors within and from command line"
23 echo "By default, the script will attempt to guess what text editor to use as much"
24 echo "as possible. You can lock with the ~/.dotfiles/config/open-editor file."
25 echo
26 echo "$0 [options] filename"
27 echo " "
28 echo "options:"
29 echo "-h, --help show brief help"
30 echo "-c, --use-code use Visual Studio Code, with the 'wait' flag"
31 echo "-n, --use-nano use GNU Nano"
32 echo "--lockfile Generate a lockfile within your home directory"
33 echo " or edit if found."
34 exit 0
35 ;;
36 -c|--use-code)
37 shift
38 echo "open-editor: Firing up your editor, please wait..."
39 sleep 3
40 if test $# -gt 0; then
41 # shellcheck disable=SC2086
42 code --wait $1
43 else
44 echo "error: no file specified, aborting..."
45 exit 1
46 fi
47 shift
48 ;;
49 -n|--use-nano)
50 shift
51 echo "open-editor: Firing up your editor, please wait..."
52 sleep 3
53 if test $# -gt 0; then
54 # shellcheck disable=SC2086
55 nano $1
56 exit
57 fi
58 shift
59 ;;
60 --lockfile)
61 shift
62 if test $# -gt 0; then
63 export OUTPUT=$1
64 else
65 echo "no output dir specified"
66 exit 1
67 fi
68 shift
69 ;;
70 -*)
71 echo "open-editor: Unsupported flag, edit the script file to customize."
72 exit 1
73 ;;
74 esac
75done
76
77if [[ $VSCODE_PATH != "" ]]; then
78 echo "open-editor: Firing up your editor, please wait..."
79 sleep 3
80 code --wait "$1"
81 exit
82elif [[ $NANO_PATH != "" ]]; then
83 echo "open-editor: Firing up your editor, please wait..."
84 sleep 3
85 nano "$1"
86 exit
87else
88 echo "open-editor: Firing up your editor, please wait..."
89 sleep 3
90 vi "$1"
91 exit
92fi