mirror of
https://github.com/chenasraf/dotfiles.git
synced 2026-05-17 17:28:07 +00:00
feat: update install script, add home ts cmds
This commit is contained in:
@@ -8,3 +8,9 @@ df:
|
||||
- .
|
||||
- utils
|
||||
|
||||
dotfiles:
|
||||
name: dotfiles
|
||||
root: ~/.dotfiles
|
||||
windows:
|
||||
- .
|
||||
- utils
|
||||
|
||||
2
.zshrc
2
.zshrc
@@ -2,8 +2,8 @@ export DOTFILES="$HOME/.dotfiles"
|
||||
export CFG="$DOTFILES/.config"
|
||||
export DOTBIN="$CFG/bin"
|
||||
|
||||
# echo 'Loading '$DOTFILES/functions.sh
|
||||
source "$DOTFILES/functions.sh"
|
||||
source "$DOTFILES/exports.sh"
|
||||
|
||||
[[ "$1" == "-q" ]] || motd
|
||||
|
||||
|
||||
16
functions.sh
16
functions.sh
@@ -346,3 +346,19 @@ xrg () {
|
||||
fi
|
||||
printf "%s\n" "$1" | xargs -I {} bash -c "$2"
|
||||
}
|
||||
|
||||
ask() {
|
||||
read -p "$1 [Y/n] " -n 1 -r
|
||||
if [[ $REPLY =~ ^[Yy]$ ]] || [[ -z $REPLY ]]; then
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
ask_no() {
|
||||
read -p "$1 [y/N] " -n 1 -r
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
@@ -159,9 +159,11 @@ rsync -vtr $DOTFILES/synced/home/.gitconfig $HOME/.gitconfig
|
||||
echo_cyan "Reloading tmux..."
|
||||
tmux source-file ~/.config/.tmux.conf
|
||||
|
||||
echo_cyan "Reloading zplug..."
|
||||
zplug clear
|
||||
zplug load --verbose
|
||||
if ask_no "Reload zplug?"; then
|
||||
echo_cyan "Reloading zplug..."
|
||||
zplug clear
|
||||
zplug load --verbose
|
||||
fi
|
||||
|
||||
echo_cyan "Done"
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#!/usr/bin/env zsh
|
||||
|
||||
# source $DOTFILES/plugins/colors.plugin.zsh
|
||||
source $DOTFILES/exports.sh
|
||||
source "$DOTFILES/exports.sh"
|
||||
source "$DOTFILES/functions.sh"
|
||||
|
||||
__home_print_help_arg() {
|
||||
echo_yellow " $1\t$2"
|
||||
|
||||
@@ -32,7 +32,7 @@ home() {
|
||||
pull | l)
|
||||
shift
|
||||
git -C "$DOTFILES" pull
|
||||
# if [[ $? -eq 0 ]]; then
|
||||
# if [[ $? -eq 0 ]]; the
|
||||
# reload-zsh
|
||||
# fi
|
||||
;;
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import * as os from 'node:os'
|
||||
import { MassargCommand } from 'massarg/command'
|
||||
import { DF_DIR, HomeOpts } from './common'
|
||||
import { massarg } from 'massarg'
|
||||
import { runCommand } from '../common'
|
||||
|
||||
const backup = async (opts: HomeOpts) => {
|
||||
const isMacOS = os.platform() === 'darwin'
|
||||
if (!isMacOS) {
|
||||
console.log('Not on MacOS, skipping backup.')
|
||||
return
|
||||
}
|
||||
await runCommand(opts, [`pushd "${DF_DIR}"`, `brew bundle dump -f --describe`, `popd`])
|
||||
}
|
||||
const backupCommand = new MassargCommand<HomeOpts>({
|
||||
name: 'backup',
|
||||
aliases: ['b'],
|
||||
description: 'Backup brew state to Brewfile',
|
||||
run: backup,
|
||||
})
|
||||
const restoreCommand = new MassargCommand<HomeOpts>({
|
||||
name: 'restore',
|
||||
aliases: ['r'],
|
||||
description: 'Restore brew state from Brewfile',
|
||||
run: async (opts: HomeOpts) => {
|
||||
await runCommand(opts, [`pushd "${DF_DIR}"`, `brew bundle`])
|
||||
},
|
||||
})
|
||||
|
||||
export const brewCommand = massarg<HomeOpts>({
|
||||
name: 'brew',
|
||||
aliases: ['b'],
|
||||
description: 'Manage Brewfile',
|
||||
})
|
||||
.main(backup)
|
||||
.command(backupCommand)
|
||||
.command(restoreCommand)
|
||||
.help({
|
||||
bindCommand: true,
|
||||
bindOption: true,
|
||||
})
|
||||
|
||||
@@ -3,6 +3,8 @@ import { Opts, runCommand, withDefaultOpts } from '../common'
|
||||
import { gitCommand, pullCommand, pushCommand, statusCommand } from './git_cmd'
|
||||
import { DF_DIR, HomeOpts } from './common'
|
||||
import { utilsCommand } from './utils_cmd'
|
||||
import { mushCommand } from './mush_cmd'
|
||||
import { brewCommand } from './brew_cmd'
|
||||
|
||||
async function sourceRun(opts: Opts, cmd: string | string[]) {
|
||||
return runCommand(opts, [`source "${DF_DIR}/.zshrc" -q`, ...(Array.isArray(cmd) ? cmd : [cmd])])
|
||||
@@ -19,6 +21,8 @@ withDefaultOpts(
|
||||
.command(pushCommand)
|
||||
.command(pullCommand)
|
||||
.command(utilsCommand)
|
||||
.command(mushCommand)
|
||||
.command(brewCommand)
|
||||
.command({
|
||||
name: 'install',
|
||||
aliases: ['i'],
|
||||
|
||||
69
utils/src/home/mush_cmd.ts
Normal file
69
utils/src/home/mush_cmd.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import * as os from 'node:os'
|
||||
import { MassargCommand } from 'massarg/command'
|
||||
import { DF_DIR, HomeOpts } from './common'
|
||||
import { massarg } from 'massarg'
|
||||
import { runCommand } from '../common'
|
||||
|
||||
const mushdir = `${os.homedir()}/Library/Application Support/CrossOver/Bottles/MushClient/drive_c/users/crossover/MUSHclient`
|
||||
|
||||
const backup = async (opts: HomeOpts) => {
|
||||
await runCommand(opts, [
|
||||
`rsync -vtr "${mushdir}" "${DF_DIR}/synced/"`,
|
||||
`echo_yellow "Copied Mushclient profile to synced folder."`,
|
||||
`git -C "${DF_DIR}" add "${DF_DIR}/synced/MUSHclient"`,
|
||||
`git -C "${DF_DIR}" commit -m "backup: mushclient"`,
|
||||
`git -C "${DF_DIR}" push`,
|
||||
`echo_yellow "Backup complete."`,
|
||||
])
|
||||
}
|
||||
const backupCommand = new MassargCommand<HomeOpts>({
|
||||
name: 'backup',
|
||||
aliases: ['b'],
|
||||
description: 'Backup Mushclient profile',
|
||||
run: backup,
|
||||
})
|
||||
const restoreCommand = new MassargCommand<HomeOpts>({
|
||||
name: 'restore',
|
||||
aliases: ['r'],
|
||||
description: 'Restore Mushclient profile',
|
||||
run: async (opts: HomeOpts) => {
|
||||
await runCommand(opts, [
|
||||
`rsync -vtr "${DF_DIR}/synced/MUSHclient/" "${mushdir}/"`,
|
||||
`echo_yellow "Restored Mushclient profile from synced folder."`,
|
||||
])
|
||||
},
|
||||
})
|
||||
const mapRestoreCommand = new MassargCommand<HomeOpts>({
|
||||
name: 'map-restore',
|
||||
aliases: ['mr'],
|
||||
description: 'Restore Mushclient map database',
|
||||
run: async (opts: HomeOpts) => {
|
||||
const src = 'Aardwolf.db.Backup_Manual'
|
||||
const bk = 'Aardwolf.db.bk'
|
||||
const dest = 'Aardwolf.db'
|
||||
|
||||
await runCommand(opts, [
|
||||
`echo_yellow "Renaming ${dest} to $bk"`,
|
||||
`pushd "${mushdir}"`,
|
||||
`mv "${dest}" "${bk}"`,
|
||||
`echo_yellow "Copying ${mushdir}/db_backups/${src} to ${mushdir}/${dest}"`,
|
||||
`cp "db_backups/${src}" "${DF_DIR}/synced/MUSHclient/${dest}"`,
|
||||
`echo_yellow "Done."`,
|
||||
'popd',
|
||||
])
|
||||
},
|
||||
})
|
||||
|
||||
export const mushCommand = massarg<HomeOpts>({
|
||||
name: 'mush',
|
||||
aliases: ['m'],
|
||||
description: 'Backup/restore Mushclient profile',
|
||||
})
|
||||
.main(backup)
|
||||
.command(backupCommand)
|
||||
.command(restoreCommand)
|
||||
.command(mapRestoreCommand)
|
||||
.help({
|
||||
bindCommand: true,
|
||||
bindOption: true,
|
||||
})
|
||||
@@ -1,5 +1,6 @@
|
||||
import * as path from 'node:path'
|
||||
import * as fs from 'node:fs/promises'
|
||||
import * as os from 'node:os'
|
||||
import { Opts, log, runCommand } from '../common'
|
||||
import {
|
||||
ParsedTmuxConfigItem,
|
||||
@@ -84,12 +85,14 @@ export async function addSimpleConfigToFile(opts: CreateOpts, config: ParsedTmux
|
||||
throw new Error(`tmux config item ${config.name} already exists`)
|
||||
}
|
||||
|
||||
const dirFix = (dir: string) => dir.replace(config.root, './').replace(os.homedir(), '~')
|
||||
|
||||
// dump config as yaml
|
||||
const contents = `
|
||||
${config.name}:
|
||||
root: ${config.root}
|
||||
windows:
|
||||
${config.windows.map((w) => ` - ${w.dir.replace(config.root, './')}`).join('\n')}
|
||||
${config.windows.map((w) => ` - ${dirFix(w.dir)}`).join('\n')}
|
||||
`
|
||||
if (opts.dry) {
|
||||
if (existingConfig[config.name]) {
|
||||
|
||||
@@ -50,14 +50,14 @@ export type TmuxLayoutType = 'row' | 'column' | 'pane'
|
||||
|
||||
export type TmuxLayout =
|
||||
| {
|
||||
type: Exclude<TmuxLayoutType, 'pane'>
|
||||
children: TmuxLayout[]
|
||||
zoom?: boolean
|
||||
}
|
||||
type: Exclude<TmuxLayoutType, 'pane'>
|
||||
children: TmuxLayout[]
|
||||
zoom?: boolean
|
||||
}
|
||||
| {
|
||||
type: 'pane'
|
||||
zoom?: boolean
|
||||
}
|
||||
type: 'pane'
|
||||
zoom?: boolean
|
||||
}
|
||||
|
||||
const defaultPanes = [
|
||||
{
|
||||
@@ -96,16 +96,16 @@ export function parseConfig(item: TmuxConfigItem): ParsedTmuxConfigItem {
|
||||
dir: path.resolve(root, w.dir),
|
||||
panes: w.panes
|
||||
? w.panes.map((p) => {
|
||||
if (typeof p === 'string') {
|
||||
return {
|
||||
dir: dirFix(path.resolve(root, w.dir, p)),
|
||||
}
|
||||
}
|
||||
if (typeof p === 'string') {
|
||||
return {
|
||||
dir: dirFix(path.resolve(root, w.dir, p.dir)),
|
||||
cmd: p.cmd,
|
||||
dir: dirFix(path.resolve(root, w.dir, p)),
|
||||
}
|
||||
})
|
||||
}
|
||||
return {
|
||||
dir: dirFix(path.resolve(root, w.dir, p.dir)),
|
||||
cmd: p.cmd,
|
||||
}
|
||||
})
|
||||
: defaultPanes,
|
||||
}
|
||||
})
|
||||
@@ -185,21 +185,21 @@ export function throwNoConfigFound() {
|
||||
[
|
||||
'tmux config file not found, searched in:',
|
||||
'\t' +
|
||||
searchDirs
|
||||
.map((x) =>
|
||||
searchPatterns('tmux')
|
||||
.map((y) => path.join(x, y))
|
||||
.join('\n\t'),
|
||||
)
|
||||
.join('\n\t'),
|
||||
searchDirs
|
||||
.map((x) =>
|
||||
searchPatterns('tmux')
|
||||
.map((y) => path.join(x, y))
|
||||
.join('\n\t'),
|
||||
)
|
||||
.join('\n\t'),
|
||||
'\t' +
|
||||
searchDirs
|
||||
.map((x) =>
|
||||
searchPatterns('tmux_local')
|
||||
.map((y) => path.join(x, y))
|
||||
.join('\n\t'),
|
||||
)
|
||||
.join('\n\t'),
|
||||
searchDirs
|
||||
.map((x) =>
|
||||
searchPatterns('tmux_local')
|
||||
.map((y) => path.join(x, y))
|
||||
.join('\n\t'),
|
||||
)
|
||||
.join('\n\t'),
|
||||
// searchInFor('tmux').map(x => path.join(d)).join('\n\t'),
|
||||
// searchInFor('tmux_local').join('\n\t'),
|
||||
].join('\n'),
|
||||
@@ -232,7 +232,7 @@ export async function fzf(opts: Opts, inputs: string[]): Promise<string> {
|
||||
fzf.stdout.setEncoding('utf-8')
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
fzf.stdout.on('readable', function () {
|
||||
fzf.stdout.on('readable', function() {
|
||||
const value = fzf.stdout.read()
|
||||
|
||||
if (value !== null) {
|
||||
|
||||
Reference in New Issue
Block a user